Created
August 22, 2012 02:12
-
-
Save masaru-b-cl/3421483 to your computer and use it in GitHub Desktop.
コレクション初期化子のoverload解決順
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Collections; | |
namespace ConsoleApplication1 | |
{ | |
class MyCollection : IEnumerable | |
{ | |
public void Add(object value) | |
{ | |
Console.WriteLine("Call object overload"); | |
} | |
public void Add(int value) | |
{ | |
Console.WriteLine("Call int overload"); | |
} | |
public void Add(string value) | |
{ | |
Console.WriteLine("Call string overload"); | |
} | |
public IEnumerator GetEnumerator() | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var col = new MyCollection { "1", 1, null, (object)null }; | |
// 実行結果 | |
// Call string overload | |
// Call int overload | |
// Call string overload | |
// Call object overload | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment