KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to hide the base public property(a data member) in my derived class: class Program { static void Main(string[] args) { b obj = new b(); obj.item1 = 4;// should show an error but it doent ??? } } class a { public int item1 {get; set;} public int item2 { get; set; } } class b : a { new private int item1; } class c : a { } i have member as public because i want the member to be inherited in c class , but want to hide the member in b class , how can i do this ? dont i have an option to selectively inherite the variable i want in my base class ??? thats really bad , i think ms should provide us with an option (may be a modifier) to perform this Edit: I found the answer myself (i heard lots of them telling this is not possible in c#, but you can kind of do it) I am including the code in case it is useful class Program { static void Main(string[] args) { b obj = new b(); obj.item1 = 4; // shows an error : ) } } class a { public int item1 { get; set; } public int item2 { get; set; } } class b : a { new public static int item1 { get; private set; } }
Tags (comma-separated)
Save Edits
Cancel