J
Jack Fox
I'm looking for a good article on efficient C# coding. All the DotNet
efficient coding articles I can find are oriented toward VB.NET, and while
some principals still apply, many do not. For instance there is no
equivalent of
with (some object)
..
end with
in C# (or somebody straighten me out).
Somehow in the my early studies of C# I got the (apparently wrong)
impression that it had some kind of great compiler that made all the good
practices I learned in VB unnecessary. Consider the following:
private static void LoadHeadings(UltraWebGrid Grid, XmlNode[]
PrevHeadingArray, SortedList FootnoteList, int CurRow)
{
for (int i = 0; i < PrevHeadingArray.Length; i++)
{
Grid.Rows[CurRow].Cells.Text =
PrevHeadingArray.Attributes["text"].Value
+
SuperFootnotes(PrevHeadingArray.SelectNodes("child::note"),
FootnoteList);
Grid.Rows[CurRow].Cells.Style.VerticalAlign =
VerticalAlign.Top;
}
}
I need to access the same cell twice, and I do it down a fairly long path.
Nowhere have I seen it advised to assign the object to a local variable and
then access it, yet when I did that the following code generated
considerably less code in the debugger disassembly:
private static void LoadHeadings(UltraWebGrid Grid, XmlNode[]
PrevHeadingArray, SortedList FootnoteList, int CurRow)
{
for (int i = 0; i < PrevHeadingArray.Length; i++)
{
UltraGridCell oCell = Grid.Rows[CurRow].Cells;
oCell.Text = PrevHeadingArray.Attributes["text"].Value
+
SuperFootnotes(PrevHeadingArray.SelectNodes("child::note"),
FootnoteList);
oCell.Style.VerticalAlign = VerticalAlign.Top;
}
}
I can't really interpret the assembler code, but I figure less code is
usually a good proxy for more efficient code.
Judging from my VB experience the next step would be to assign
"PrevHeadingArray.Length" to a local integer. Am I on the right track?
I really don't have the time to pursue these interesting investigations, and
I haven't taken the time to instrument the example above and see what the
comparative elapsed times are, I would much rather read this all spelled-out
somewhere.
efficient coding articles I can find are oriented toward VB.NET, and while
some principals still apply, many do not. For instance there is no
equivalent of
with (some object)
..
end with
in C# (or somebody straighten me out).
Somehow in the my early studies of C# I got the (apparently wrong)
impression that it had some kind of great compiler that made all the good
practices I learned in VB unnecessary. Consider the following:
private static void LoadHeadings(UltraWebGrid Grid, XmlNode[]
PrevHeadingArray, SortedList FootnoteList, int CurRow)
{
for (int i = 0; i < PrevHeadingArray.Length; i++)
{
Grid.Rows[CurRow].Cells.Text =
PrevHeadingArray.Attributes["text"].Value
+
SuperFootnotes(PrevHeadingArray.SelectNodes("child::note"),
FootnoteList);
Grid.Rows[CurRow].Cells.Style.VerticalAlign =
VerticalAlign.Top;
}
}
I need to access the same cell twice, and I do it down a fairly long path.
Nowhere have I seen it advised to assign the object to a local variable and
then access it, yet when I did that the following code generated
considerably less code in the debugger disassembly:
private static void LoadHeadings(UltraWebGrid Grid, XmlNode[]
PrevHeadingArray, SortedList FootnoteList, int CurRow)
{
for (int i = 0; i < PrevHeadingArray.Length; i++)
{
UltraGridCell oCell = Grid.Rows[CurRow].Cells;
oCell.Text = PrevHeadingArray.Attributes["text"].Value
+
SuperFootnotes(PrevHeadingArray.SelectNodes("child::note"),
FootnoteList);
oCell.Style.VerticalAlign = VerticalAlign.Top;
}
}
I can't really interpret the assembler code, but I figure less code is
usually a good proxy for more efficient code.
Judging from my VB experience the next step would be to assign
"PrevHeadingArray.Length" to a local integer. Am I on the right track?
I really don't have the time to pursue these interesting investigations, and
I haven't taken the time to instrument the example above and see what the
comparative elapsed times are, I would much rather read this all spelled-out
somewhere.