Lm Martiness

Lm Martiness

  • NA
  • 107
  • 8.1k

How to fill class with data c#

Jun 14 2020 5:05 AM
Hi everyone. I am trying to fill class with data and use these data anywhere else on the program, where i Will need it.
 
I created this class
  1. public class id  
  2. {  
  3. private string name; // field  
  4. public string Name // property  
  5. {  
  6. get { return name; } // get method  
  7. set { name = value; } // set method  
  8. }  
  9. }  
And in form_name i tried to fill the class on this way:
  1. private void Button_Click(object sender, RoutedEventArgs e)  
  2. {  
  3. id IDOBJE = new id();  
  4. {  
  5. IDOBJE.Name = txtshenimi.Text;  
  6. }  
  7. this.Close();  
  8. }  
  9. }  
And in another form i tried to retrieve data like this:
  1. private void Button_Click_1(object sender, RoutedEventArgs e)  
  2. {  
  3. id idobje = new id();  
  4. txtrez.Text = idobje.Name;  
  5. }  
But I don't get any result. Could someone help me to clarify this, cause i am new to OOP, and don't know so much about classes, and objects.

Answers (2)