How are strings passed in .NET?
问题 When I pass a string to a function, is a pointer to the string's contents passed, or is the entire string passed to the function on the stack like a struct would be? 回答1: To answer your question, consider the following code: void Main() { string strMain = "main"; DoSomething(strMain); Console.Write(strMain); // What gets printed? } void DoSomething(string strLocal) { strLocal = "local"; } There are three things you need to know in order to predict what will happen here, and to understand why