Question: 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?

Answer: 
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 `private` access modifier but you have to use `internal` in this way:

```
class newClient
{
    public int ID { get; set; }
    public string Name { get; set; }
    public ClientExtraData clientExtraData{ get; set; }

    public newClient()
    {
        clientExtraData = new ClientExtraData();
    }

    internal class ClientExtraData
    {
        public string ExtraField1 { get; set; }
        public string ExtraField2 { get; set; }
    }
}

```

Or you can make `ClientExtraData` `public` instead of `internal` if you want to make it accessible outside `newClient` in this way:

```
newClient.ClientExtraData clientExtraData = new newClient.ClientExtraData();

```

---

So then you can do:

```
newClient nclnt= new newClient();
string s = nclnt.clientExtraData.ExtraField1;

```
1. Make the inner class public so that it can be accessed.
2. Make the property you need to access as static (or create instance to access the field)

class newClient
 {
 public int ID { get; set; }
 public string Name { get; set; }

```
    public class ClientExtraData
    {
        public static string ExtraField1 { get { return "10"; }  }
        public string ExtraField2 { get; set; }
    }
}

```

Access code:

newClient nclnt = new newClient();
string s = newClient.ClientExtraData.ExtraField1;