Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi, I have a small question! It is simple and easily solved!

I have a Form1 with some fields

C#
private int selectedSkolotajuID = 0;
        private int selectedSkolenuID = 0;
        private int selectedTestID = 0;


And I created new windows form Form2

how I can inherit those fields in my new Form2

:)
Posted

1 solution

No. They are private. If you want them to be accessible in derived classes, then mark them as protected, for the same namespace use internal and for anyone make them public.

However, the best way to do it is to leave them as private and create more open properties to access them. That way you can change your form internals without affecting outside elements.
For example:
private int selectedSkolotajuID = 0;
public int SelectedSkolotajuID
   {
   get { return selectedSkolotajuID; }
   set {selectedSkolotajuID = value;}
   }
 
Share this answer
 
Comments
valza 24-Nov-10 3:45am    
thanks! :)
Dalek Dave 24-Nov-10 4:15am    
Good Call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900