class Program
{
static void Main(string[] args)
{
Program p = new Program();
开发者_StackOverflow社区 string s = p.ToString();
Console.WriteLine(s.Length);
Console.Read();
}
}
The output I am receiving is 27 Why?
Because the string representation of Program class, basically it's full name (namespace and class name) as string has this number of characters.
The default implementation of the ToString
method is to return the name of the type, so your string s
contains the full type name of the Program
class, i.e. something like "MySecondTestProgram.Program"
, and that is what you are getting the length of.
精彩评论