开发者

output for the following c# snippet [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.
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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜