Monday, November 25, 2013

Using Methods and Classes

Methods I have a good idea on how to use and set them up. The bigger problem I have is that I have a very hard time under standing classes and how to use them. So this just has me all so confused.So I went back to my old console application to see if I can try and learn how to make and use classes, Below is a very simple class.



public class cfgInfo
{
public string bbsName { get; set; }
public string sysopname { get; set; }
public bool logs { get; set; }
public int adminAccess { get; set; }
public int userAccess { get; set; }

public cfgInfo(string BBSName)
{
bbsName = BBSName;
}
}

This is the configuration class for the console application. To make a long story short. Look at the code below.



public static void getsys()
{

if (!File.Exists(ppath + cfgfile))
{
Directory.CreateDirectory(ppath);
StreamWriter sw = File.CreateText(ppath + cfgfile);

sw.WriteLine("BBS Name"); // BBS Name
sw.WriteLine("Sysop Name"); //Sysops Name
sw.WriteLine("y"); //Ok
sw.WriteLine("99"); //Admin Access
sw.WriteLine("10"); //User Access
sw.Close();

}

StreamReader rw = File.OpenText(ppath + cfgfile);

var Info = new cfgInfo(rw.ReadLine()); //BBS Name
//MyDoor.Program.bbsname = rw.ReadLine();
Info.sysopname = rw.ReadLine(); // Sysops Name
//MyDoor.Program.sysname = rw.ReadLine();

string YN = rw.ReadLine().ToUpper();
if (YN == "Y")
Info.logs = true;
else
Info.logs = false;


Info.adminAccess = Convert.ToInt32(rw.ReadLine());
//MyDoor.Program.sysopaccess = rw.ReadLine();
Info.userAccess = Convert.ToInt32(rw.ReadLine());
//MyDoor.Program.useraccess = rw.ReadLine();
rw.Close();

This part of the code creates the cfg file if it's not fount. any way it loads in and reads the lines one at a time. and gets 5 lines from the file. As you can see I use the class for this. The problem is. I can't use it any where else in my application. Sense I can only use this in side a method. I didn't want to create 5 new static vars just to hold these in. So may be I'm getting the wrong idea about classes.


Now VS C# has 1000's of name spaces and class library's that I have use 100's of times. But creating and using my own classes is a pain in the butt. So am I getting the wrong idea about classes and how to use them. Are classes confined only too methods. Some one please tell me. ??????


Joe M.




Pro-Forums

Delta Force Barracks

On the Frontlines


No comments:

Post a Comment