看板 C_Sharp 關於我們 聯絡資訊
前幾天在網路上看到一個有趣的C# quiz, 貼出來試試看 以下的程式可否 compile, 為什麼? using System; using System.Collections.Generic; class Program { static void Main(string[] args) { IEnumerable<Inter1> ienum1 = new Class1[] { new Class1() }; foreach (Class2 c in ienum1) { Console.WriteLine(c); } } } public interface Inter1 { } public class Class1 : Inter1 { } public class Class2 { } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 67.161.17.127
tomex:跟Class2有關係嗎? 11/25 23:08
chhuang:http://0rz.tw/c53ja yes it compiles, and here's why 11/25 23:11
liunate:po在這邊的題目敘述有完整嗎? 12/16 11:40