2013-03-21 81 views

回答

1

這是因爲它返回所有t的重載從結構的Int32

enter image description here

+0

我只是upvoted你,因爲圖像=) – 2013-03-21 15:10:54

+0

謝謝,一張圖片勝過千言萬語:) – 2013-03-21 15:20:53

1

可能是它的整個繼承樹。嘗試通過BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnlyGetMethods

4

因爲Int32.ToString() has four overloads。您可以輕鬆地設置一個斷點看到這一點,檢查intType.GetMethods()結果,在那裏你會看到(其中包括):

[5] {System.String ToString()} 
[6] {System.String ToString(System.String)} 
[7] {System.String ToString(System.IFormatProvider)} 
[8] {System.String ToString(System.String, System.IFormatProvider)} 
+1

+1他字符串方法:布拉沃!!!!!! – 2013-03-21 14:58:29

2

因爲Type.GetMethods()回報所有重載這種類型的方法。

Int32.ToString()方法都有4個重載,所以......

System.String ToString() 
System.String ToString(System.String) 
System.String ToString(System.IFormatProvider) 
System.String ToString(System.String, System.IFormatProvider) 
2

的原因是,有更多的的方法,不僅僅是一個名字:

Type intType = typeof(Int32); 

foreach(var v in intType.GetMethods()) 
    Console.WriteLine(v.Name + " " + 
        (v.IsStatic? "static " : "") + 
         string.Join(", ", v.GetParameters() 
             .Select(p => p.ParameterType.Name + " " + p.Name))); 

將打印

CompareTo Object value 
CompareTo Int32 value 
Equals Object obj 
Equals Int32 obj 
GetHashCode 
ToString 
ToString String format 
ToString IFormatProvider provider 
ToString String format, IFormatProvider provider 
Parse static String s 
Parse static String s, NumberStyles style 
Parse static String s, IFormatProvider provider 
Parse static String s, NumberStyles style, IFormatProvider provider 
TryParse static String s, Int32& result 
TryParse static String s, NumberStyles style, IFormatProvider provider, Int32& result 
GetTypeCode 
GetType