我工作的一个小应用程序来获得与C#中的交手,我已经写了一个小程序,目前加起来的项目(目前预定义)这里的值是我到目前为止有:代码重构C#
//Defining classes
public class Item1{
public string Type{get{return "Item1";}}
}
public class Item2{
public string Type{get{return "Item2";}}
}
//Methods
public void CalcItems(Item1 item1, int val){
this.Log(item1.Type + "Val:" + val);
this.total += val;
}
public void CalcItems(Item2 item2, int val){
this.Log(item2.Type + "Val:" + val);
this.total += val;
}
//Calling these methods
Items.CalcItems(new Item1(), 30);
Items.CalcItems(new Item2(), 12);
如何通过一种计算方法传递Item1和Item 2?
“group”是什么意思?你是否希望'Item1'和'Item2'被传递给相同的'CalcItems'方法? – Jamiec
@Jamiec是的,通过这两个项目通过相同的方法。对不起找不到措辞哈哈 – John