Pros & Cons of var datatype in .net 3.5

Possible Duplicates: Use of var keyword in C# Use of “var” type in variable declaration Hello everybody, "Var keywork it require explicitly type casting Avoid boxing and unboxing value types where possible." Is it advisable to use var keyword instead of explicit datatype? From ReSharper Horizons blog: It induces better naming for local variables. When you read local varia

.net 3.5中var数据类型的优缺点

可能重复: 在C#中使用var关键字 在变量声明中使用“var”类型 大家好, “var keywork需要明确地进行类型转换尽可能避免装箱和拆箱值类型。” 建议使用var关键字而不是显式数据类型? 来自ReSharper Horizo​​ns博客: 它为局部变量提供了更好的命名。 当你使用显式类型读取局部变量声明时,在那个时候你有更多的信息,并且像“IUnitTestElement current”这样的东西是有意义的。 但是,稍后使用此局部变量时,您会看

Why C# Need Integral Types already it has "Var" keyword?

This question already has an answer here: Use of var keyword in C# 86 answers in no particular order... var is only a compiler construct; even var i = 4; is typed as int C# hasn't always had var , and you can't remove keywords without utterly breaking existing code. you can only use var in method variables - not fields, parameters, return types etc. most people are happy to

为什么C#需要集成类型已经有了“Var”关键字?

这个问题在这里已经有了答案: 在C#86中使用var关键字的答案 没有特别的顺序...... var只是一个编译器构造; 甚至var i = 4; 键入为int C#并不总是有var ,并且不能彻底地破坏现有的代码而删除关键字。 你只能在方法变量中使用var - 不是字段,参数,返回类型等。 大多数人都乐意在var中输入int ! 尤其是当型事项,并有字节,浮点型,枚举,小数等与文字的所有工作0 ; 即short x = 0; int y = 0; long z = 0;

Advantage of var keyword in C# 3.0

Duplicate: What to use var or object name type I couldn't understand the need of var keyword in C# 3.0 What is the advantage in using it. i saw this question but did not understand the real purpose of using it It's mostly present for LINQ, when you may use an anonymous type as the projection: var query = from person in employees where person.Salary > 10000m

C#3.0中var关键字的优点

重复: 什么使用var或对象名称类型 我无法理解C#3.0中var关键字的需求使用它的优点是什么? 我看到这个问题,但不明白使用它的真正目的 它主要针对LINQ,当您可以使用匿名类型作为投影时: var query = from person in employees where person.Salary > 10000m select new { FullName=person.Name, person.Department }; 这里query的类型不能显式声明,因为匿名类型没有名字。 (在现实世

var vs explicit declaration

Possible Duplicate: Use of var keyword in C# Hi, Just moved job and I am used to using var a lot. At my previous job we were doing lots of TDD and using resharper. In this job they hate third party tools and the developers here say that it is not good to use var all the time and it is not as efficient as explicit typing. Some time ago I thought the same but now I have gotten so used to i

var vs显式声明

可能重复: 在C#中使用var关键字 嗨,刚搬家的工作,我习惯使用var很多。 在我以前的工作中,我们正在做大量的TDD并使用resharper。 在这份工作中,他们讨厌第三方工具,这里的开发人员说,一直使用var并不是很好,它不像显式类型那样高效。 前一段时间,我认为是相同的,但现在我已经习惯了它,它使我的代码更加整洁。 我已经阅读了一些文章,看起来似乎是混淆了它是否有效。 我读过使用var产生相同的IL代码。 那

What advantages does using var have over the explicit type in C#?

Possible Duplicates: What's the point of the var keyword? Use of var keyword in C# I understand how IEnumerable<...> for a datatype can make the code a little less readable or how nested generics can seem a little daunting. But aside from code readability, are there advantages to using var instead of the explicit type? It seems like by using the explicit type, you'd better c

使用var对C#中显式类型有什么优势?

可能重复: var关键字有什么意义? 在C#中使用var关键字 我明白IEnumerable<...>对于一个数据类型如何使得代码可读性差一点,或者嵌套泛型如何看起来有点让人望而生畏。 但是除了代码可读性之外,使用var而不是显式类型有什么优势? 这似乎是通过使用显式类型,你最好传达变量的能力,因为你知道它是什么。 如果这是一个职场编码标准,我会为了团队合作而使用它。 然而,在我自己的项目中,我更愿意避免var的

C# var keyword usage

Possible Duplicates: What to use: var or object name type? Use of var keyword in C# What's the point of the var keyword? Should I always favour implictly typed local variables in C# 3.0? I have just installed a trial version of ReSharper to evaluate it for my company. One thing that I have noticed is it is suggesting that I change the following (made up example): string s = ""; t

C#var关键字使用情况

可能重复: 使用什么:var或对象名称类型? 在C#中使用var关键字 var关键字有什么意义? 我是否应该总是在C#3.0中使用隐式类型化的局部变量? 我刚刚安装了ReSharper的试用版,为我的公司进行评估。 我注意到的一件事是建议我改变以下内容(例如): string s = ""; 至 var s = ""; 在声明变量时,最好使用var关键字而不是使用对象类型? 它给了什么好处。 对于上下文,我是一位刚刚过渡到.Net作品的前Java开

C# 'var' keyword versus explicitly defined variables

This question already has an answer here: Use of var keyword in C# 86 answers So, is there some sort of performance gain to be had from changing the List to a var No but this is not the only valid reason for a refactoring. More importantly, it removes redundance and makes the code shorter without any loss in clarity. I've always been taught that explicitly defining a variable, rather

C#'var'关键字与显式定义的变量

这个问题在这里已经有了答案: 在C#86中使用var关键字的答案 那么,将List改为var会有什么样的性能提升 不,但这不是重构的唯一有效原因。 更重要的是,它消除了冗余,并使代码缩短而不会造成任何损失。 我总是被教导明确定义一个变量,而不是使用动态变量,这是更优化的。 你误解了var意思。 这不是动态的,因为它会产生相同的输出。 这只是意味着编译器会自行计算变量的类型。 它显然有能力这样做,因为这是用

What to use: var or object name type?

This question already has an answer here: Use of var keyword in C# 86 answers Beyond the obvious use of var with LINQ, I also use it to abbreviate hairy variable declarations for readability, eg: var d = new Dictionary<string, Dictionary<string, Queue<SomeClass>>>(); In general, I get a kind of comfort (for want of a better word) from static typing that makes me reluctant

使用什么:var或对象名称类型?

这个问题在这里已经有了答案: 在C#86中使用var关键字的答案 除了明显使用var与LINQ之外,我还使用它来缩写多变的变量声明以提高可读性,例如: var d = new Dictionary<string, Dictionary<string, Queue<SomeClass>>>(); 一般来说,我从静态输入中获得一种舒适(因为想要更好的词),这让我不愿放弃。 我喜欢这种感觉,即当我声明一个变量时,我知道自己在做什么。 声明一个变量不仅仅是告诉编译器

What does "var" mean in C#?

Possible Duplicate: Use of var keyword in C# In C#, how does keyword " var " work? It means that the type of the local being declared will be inferred by the compiler: // This statement: var foo = "bar"; // Is equivalent to this statement: string foo = "bar"; Notably, var does not define a variable to be of a dynamic type. So this is NOT legal: var foo = "bar"; foo = 1; // Com

“var”在C#中的含义是什么?

可能重复: 在C#中使用var关键字 在C#中,关键字“ var ”是如何工作的? 这意味着声明的本地类型将由编译器推断出来: // This statement: var foo = "bar"; // Is equivalent to this statement: string foo = "bar"; 值得注意的是, var没有将变量定义为动态类型。 所以这是不合法的: var foo = "bar"; foo = 1; // Compiler error, the foo variable holds strings, not ints var只有两个用途: 它需要更少的

IDictionaryEnumerator is not an iterator interface type?

I'm trying to port some code that uses Hashtable to an environment that doesn't have this class. So I thought about not messing with the code and just create my own Hashtable from Dictionary , like this: public class Hashtable : Dictionary<Object, Object> { // ... new public IDictionaryEnumerator GetEnumerator() { var ie = base.GetEnumerator(); while

IDictionaryEnumerator不是一个迭代器接口类型?

我试图将一些使用Hashtable代码移植到没有这个类的环境中。 所以我想过不要搞乱代码,只需从Dictionary创建我自己的Hashtable ,就像这样: public class Hashtable : Dictionary<Object, Object> { // ... new public IDictionaryEnumerator GetEnumerator() { var ie = base.GetEnumerator(); while (ie.MoveNext()) yield return new DictionaryEntry(ie.Current.Key, ie.Cu