Here is sometking I was not privy to and ran across by accident... Nesting Classes.
Take a look at the following Class declaration. Notice that there is a public class inside the first class.
Another interesting point to note is that the private static fields of the containment class are available to the nested class. This can come in useful when you have worker variables that are messy if you expose them as public but necessary between class instances.
namespace Test.ServiceClassAssembly
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ServiceClass
protected static string _privateString = "parent private string value";
public ServiceClass()
//
// TODO: Add constructor logic here
}
public string GetTestValue()
return "Version 1";
public class nestedService
private string _nestedVal = "I am a nested Class value";
public string GetNestedTestValue()
string sParentVal = _privateString;
string sLocalVal = _nestedVal;
return "ParentVal:" + _privateString + ", LocalVal:" + _nestedVal;
...Accessing the nested and containment class is as follows
Test.ServiceClassAssembly.ServiceClass sc = new Test.ServiceClassAssembly.ServiceClass ();
_serviceClassReturnValue = sc.GetTestValue();
Test.ServiceClassAssembly.ServiceClass.nestedService ns = new Test.ServiceClassAssembly.ServiceClass.nestedService();
_serviceClassNestedReturnValue = ns.GetNestedTestValue();
...The result?
There's a short little article that might come in handy