我想知道这两个实例化之间的区别
interface ITest
{
int TotalMarks(int englishMarks, int mathematicsMarks);
}
class TestClass : ITest
{
public int TotalMarks(int engMarks, int mathMarks)
{
return engMarks + mathMarks;
}
}
class Program
{
static void Main(string[] args)
{
TestClass c = new TestClass();
Console.Write(c.TotalMarks(10, 20));
Console.Write("\n");
ITest c1 = new TestClass();
Console.Write(c1.TotalMarks(21, 34));
Console.ReadKey();
}
}
Run Code Online (Sandbox Code Playgroud)
TestClass c = new TestClass(); ITest c1 = new TestClass();
他们都按预期工作并给出结果.这两个如何不同以及何时使用哪个?