Is it possible to access a parent member in a child class...
class MainClass {
class A { Whatever }
class B {
List<A> SubSetList;
public void AddNewItem(A NewItem) {
Check MasterListHere ????
}
}
List<A> MasterList;
}
So... my main class will have a master list. It will also have a bunch of instances of B. In each instance of B, I want to add new A's to the particular B, but only if they exist in the Master List. I toyed with making the MasterList static and it works ... until I have more than one instance of MainClass... which I will have.
I could pass a reference to MasterList to each instance of B, but I will eventually have multiple of these "MasterLists" and i don't want to have to pass lots of references if i don't have to.
C is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, and so on. C programming is an excellent language to learn to program for beginners. Our C tutorials will guide you to learn C programming one step at a time.
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
" " C is a computer programming language. That means that you can use C to create lists of instructions for a computer to follow. C is one of thousands of programming languages currently in use.
C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.
In C# there is actually no implicit reference to the instance of the enclosing class, so you need to pass such a reference, and a typical way of doing this is through the nested class' constructor.
You can use something like this:
class B {
private MainClass instance;
public B(MainClass instance)
{
this.instance = instance;
}
List SubSetList;
public void AddNewItem(A NewItem) {
Check MasterListHere ????
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With