告诉我如何使用新的“动态” C#4.0中的关键字 [英] Show me the way to use new "dynamic" keyword in C# 4.0
本文介绍了告诉我如何使用新的“动态” C#4.0中的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是新版本的4.0版,被称为动态版。告诉我我在代码中可以使用的方式,以及这个未来可以帮助我吗?
相关问题: p>
解决方案
我们在TDD中使用C#dynamic关键字。
此代码不会编译,因为方法Addition未实现
[TestMethod )]
public void CalculatorThingAdd_2PositiveNumbers_ResultAdded()
{
CalculatorThing myCalculator = new CalculatorThing();
int result = 0;
int expcected = 3;
// - > CalculatorThing不包含'Addition'的定义
result = myCalculator.Addition(1,2);
Assert.AreEqual(result,expcected);
}
使用动态关键字代码编译,测试失败! - > TDD
Here is new C# future in version 4.0 known as dynamic. Show me the way i can use it in my code and how this future can help me?
Related questions:
- Does the new ‘dynamic’ C# 4.0 keyword deprecate the ‘var’ keyword ?
- What do you think of the new C# 4.0 ‘dynamic’ keyword?
解决方案
We use the C# "dynamic" keyword with TDD.
This code doesn't compile because the method "Addition" is not implemented
[TestMethod()]
public void CalculatorThingAdd_2PositiveNumbers_ResultAdded()
{
CalculatorThing myCalculator = new CalculatorThing();
int result = 0;
int expcected = 3;
// --> CalculatorThing does not contain a definition for 'Addition'
result = myCalculator.Addition(1, 2);
Assert.AreEqual(result, expcected);
}
With the "dynamic" keyword the code compiles and the test fails! --> TDD
See answer here https://stackoverflow.com/questions/244302/what-do-you-think-of-the-new-c-4-0-dynamic-keyword/2243818#2243818
这篇关于告诉我如何使用新的“动态” C#4.0中的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文