Did you ever wonder......
Is there any difference in terms of performance between declaring a variable outside of a loop like this...
string str = "";
for (int i = 0; i < 10; i++)
{
str = "hello";
}
...versus declaring the variable within a loop and using it like this:
for (int i = 0; i < 10; i++)
{
string str = "hello";
}
So what do you think???!!! The asnwer in this case will be:
The first example is actually slower, because it causes one more string allocation to occur. In c# the "creation" of variables is always moved to the top of methods in the compiled IL. Therefore your second example is exactly the same performace as:
string str;
for (int i = 0; i < 10; i++)
{
str = "hello";
}
Notice this does not assign an initial value to str of "".
Showing posts with label .NET Framework. Show all posts
Showing posts with label .NET Framework. Show all posts
Thursday, November 1, 2007
Sunday, December 3, 2006
Tools and Software Components for the .NET Framework
Every developer loves Tools and Software Components that make his life easier.
On of the most updated list of tools, that also explain each on of them, can be found under:
http://www.dotnetframework.de/dotnet/produkte/tools.aspx?t=tools&kat=
Enjoy :-)
On of the most updated list of tools, that also explain each on of them, can be found under:
http://www.dotnetframework.de/dotnet/produkte/tools.aspx?t=tools&kat=
Enjoy :-)
Labels:
.NET,
.NET Framework,
C#,
Software Components,
Tools
Subscribe to:
Posts (Atom)