I would like to keep my .cs files separate, mainly because I think it looks neater that way. In one .cs file I have the Form.cs. I’m working in the .NET framework 2.0. So I have a different myClass.cs file with several methods. As I want users of the form to give authentication before accessing the web services called in the method, I want the information to be private.
I’ve seen in examples and tutorials that this is no problem normally within the same file. However, in my goal I want the info to be in the class.cs file.. For example I want the class in myClass.cs file to look like this (this is rough yet):
private class SessionData
{
private String fTicket;
private string otherData;
public SessionData( String ticket, String otherData)
{
fTicket = ticket;
fotherData = otherData;
}
public String getTicket{ return fTicket; };
}
And then access it in the form.cs file…
private void LogOn_Click(object sender, EventArgs e)
{
myClass sessInfo = new myClass();
string myTicket = sessInfo.SessionData();
}
}
The problem is that because it’s private I can’t access it in Form.cs. Is it even possible to do this? I’ve seen a bunch of examples and tips but always within the same file.
This is the basic idea anyways that’s in my head. If there is another way I’m open for advice!
Do I have to make a public constructor and can someone point me to an example?
You could define the nested class in a seperate file for example ‘SessionData.cs’ by just wrapping it inside the partial class which should have access to it.