i have a little function that goes like this:
void Bar(string s)
{
*/ do somthing with the string here.*/
}
void Foo()
{
Bar("Hello");
}
if i look at the IL output, it gives me the following:
.method private hidebysig instance void Foo() cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: ldstr "Hello"
L_0006: call instance void TestApp.MainWindow::Bar(string)
L_000b: ret
}
now i thought i'd replace it with a const string field for it.
const string str= "Hello";
void Foo()
{
Bar(str);
}
that translates TO THE EXACT SAME IL snippet.
now my question is which one to use?
Foo("Hello"); or Foo(cHello);
Thank you for your help!
--------------EDIT-------------------
To be more specific, i use this for Logging purposes to add a prefix to a message:
AND it would only appear once in code!
so it looks more like this:
void LogDebug(string msg)
{
Log("[DEBUG]", msg)
}
void Log(string pre, string msg)
{
// generates an output in form of
// pre + msg
}
:)