Strings are immutable in .NET. What that means is every operation, every
change, any time you change a string, and new string is created and the old
one is marked for GC.
string s = "hello";
s = s.Replace( "hell", "heaven" );
Two strings were created. I think there is actually more because the string
literals must be loaded.
IMHO, it is more a style issue. I like to have strings declared inside my
methods, they are marked for GC faster when the methods exits, rather than
when the Page is done processing a request.
HTH,
bill
"darrel" <no*****@hotmail.com> wrote in message
news:uJ**************@TK2MSFTNGP11.phx.gbl...
Often, I want to use a string in multiple functions on a page. I can
declare and re-set the string in each function, or I can just delcare the string
outside of the individual functions so that they can all see it.
This works fine.
My question is if there is any reason NOT to go ahead and declare ALL
strings at the top? Is there a performance/memory hit in doing that? Or is
it simply a matter of clean code syntax/layout?
-Darrel