1.創建一個舊的類 }
public class OldClass
{
public string[] names = new string[3] { "大學英語", "計算機組成原理", "計算機體系結構" };
}
2.創建一個新的接口滿足現在的需求
public interface INew
{
void SelectData();
}
3.創建一個適配器,使舊類裡面的字符串數組轉換成一個泛型;
public class Adapter : INew
{
private OldClass data = new OldClass();
public void SelectData()
{
List
_Course.AddRange(data.names);
foreach (var a in _Course)
{
System.Console.WriteLine(a);
}
System.Console.ReadLine();
}
}
4.在主函數裡面進行調用輸出;
class Program
{
static void Main(string[] args)
{
INew _new = new Adapter();
_new.SelectData();
}