Ok I'm making something sort of on the fly and I have learned it's not a good way. That said I was wondering something that
is pretty simple but I'm not sure about. That is should I just put all my methods on the same page as my form controls
and what not? or should I make a new class and store them there.
I'm not doing anything mind blowing just some averaging on numbers that I pulled form a file and the like. I have this
block of code, should I make it into a method on a new class page or just make it a method on the page the controls
are on.
Code:
foreach (string s in fileNames)
{
int lineCount = 0;
string line;
string strHold;
double someDoubleVar;
StreamReader file = new StreamReader(s);
while ((line = file.ReadLine()) != null)
{
strHold = line.Replace("\"","");
if (lineCount == 15)
{
holder = strHold.Split(',');
if (Double.TryParse(holder[2], out someDoubleVar)) { elong.Add(someDoubleVar);}
if (Double.TryParse(holder[3], out someDoubleVar)) { breakStr.Add(someDoubleVar); }
if (Double.TryParse(holder[4], out someDoubleVar)) { mod.Add(someDoubleVar); }
break;
}
lineCount++;
}
}
Generally breaking code into functional pieces have to do a) with reusability b) with readability
When you will revisit this code instead of seeing this block of code you'll have a forexample ParseThisStuff( string FileNamePath);
So in a glimpse you will know what it does and also you can reuse it elsewhere.
Personaly, I try to keep the less possible code with the control. Either making a library, so I can just replace the assmbly (and keeping app's assembly small) or if not possible, I'm breaking the control's (partial) class into parts with specific naming.
Bookmarks