I hope it is ok to ask this sort of question, if it is not appropriate please delete the post and I will know what is appropriate.
I am learning C# and I am trying to 'refactor' my code (which is one huge 1,000 line Win Form. So I created my first class library and I just wanted to run it by people that know a LOT more than I do to see if there are improvements, or if I have misunderstood the way to implement it - which is entirely possible.
I created a Class called FileName.cs to handle all of the filenames that I use throughout the Win Form.
I know that Date has become superfluous in the above code - it wasn't always, but I am testing a different naming convention to improve functionality.
At the very top of my Form1.cs I refer to the objects that I need to create:
Then whenever I need to refer to a file I use a single line of code - for each file:
While technically, I was using a single line of code anyway (just setting the variable to a string of "Path + Name" - this has helped me enormously when it came to changing the naming convention - which I just did....I just changed the class method and all of the names were changed throughout, so there is real benefit to doing it this way and I would like to take another step in refactoring the code into classes, but before I go ahead and do that I wanted to seek some advice to make sure I wasn't completely misunderstanding the basics.
Self teaching, easy to teach yourself mistakes.
I am learning C# and I am trying to 'refactor' my code (which is one huge 1,000 line Win Form. So I created my first class library and I just wanted to run it by people that know a LOT more than I do to see if there are improvements, or if I have misunderstood the way to implement it - which is entirely possible.
I created a Class called FileName.cs to handle all of the filenames that I use throughout the Win Form.
C#:
public class FileName
{
public string Path { get; set; }
public string Date { get; set; }
public string Name { get; set; }
public string CombinedName(string name)
{
Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\";
Date = DateTime.Now.ToString("yyyyMMdd");
this.Name = name;
return Path + Name;
}
}
I know that Date has become superfluous in the above code - it wasn't always, but I am testing a different naming convention to improve functionality.
At the very top of my Form1.cs I refer to the objects that I need to create:
C#:
FileName DataSetOne = new FileName();
FileName DataSetTwo = new FileName();
FileName DataSetFull = new FileName();
FileName DataSetExcel = new FileName();
Then whenever I need to refer to a file I use a single line of code - for each file:
C#:
string DS1 = DataSetOne.CombinedName("DataSet1.txt");
string DS2 = DataSetTwo.CombinedName("DataSet2.txt");
string DF1 = DataSetFull.CombinedName("fulldataset.txt");
While technically, I was using a single line of code anyway (just setting the variable to a string of "Path + Name" - this has helped me enormously when it came to changing the naming convention - which I just did....I just changed the class method and all of the names were changed throughout, so there is real benefit to doing it this way and I would like to take another step in refactoring the code into classes, but before I go ahead and do that I wanted to seek some advice to make sure I wasn't completely misunderstanding the basics.
Self teaching, easy to teach yourself mistakes.