I want to define a class inside a class.
example:
private class newClient
{
public int ID { get; set; }
public string Name{ get; set; }
private class ClientExtraData
{
public string ExtraField1 { get; set; }
public string ExtraField2 { get; set; }
}
}
now i want to access the ExtraField1 in such way:
newClient nclnt= new newClient();
string s=nclnt.ClientExtraData.ExtraField1;
Can this be done?
No you can’t access the internal class in this way
nclnt.ClientExtraData.ExtraField1;because you must have an instance of that object if you want to access its properties.Then you can’t use the
privateaccess modifier but you have to useinternalin this way:Or you can make
ClientExtraDatapublicinstead ofinternalif you want to make it accessible outsidenewClientin this way:So then you can do: