Difference of “var”s in C#, VB and Javascript
2011-08-05 07:55
363 查看
varType "var" is commonly used in C#, but do not confuse var with the concept of a VB variant (it's not), nor with the concept of var in dynamic languages like JavaScript (where var really means object).
In these languages the variable's type can change, and so type checking is performed at run-time increased flexibility at the cost of safety.
In C# 3.0 the type cannot change, and all type checking is done at compile-time.
For example, if the inferred type is object (as for obj6 below), in C# 3.0 you end up with an object reference of very little functionality:
In these languages the variable's type can change, and so type checking is performed at run-time increased flexibility at the cost of safety.
In C# 3.0 the type cannot change, and all type checking is done at compile-time.
For example, if the inferred type is object (as for obj6 below), in C# 3.0 you end up with an object reference of very little functionality:
object obj5 = "hi"; // obj5 references the string "hi!", but type is object var obj6 = obj5; // obj6 also references "hi!", with inferred type object string s1 = obj6.ToUpper(); // ERROR: 'object' does not contain 'ToUpper'
相关文章推荐
- JavaScript Var 'Undefined' in Firefox; IE and Opera Work fine
- Addin and Automation Development In VB.NET 2003 (3)
- Prototypes and Inheritance in JavaScript
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- 如何使用<Beginning ASP.NET 3.5 in C# and VB>书中的示例代码
- Timing and Synchronization in JavaScript
- [转] Try to use one var statement per scope in JavaScript
- 从内部和外部的js文件中获取ASPX页面的控件ClientID(get control reference from inline and external javascript)
- 京JS 2013 - A two-day conference in Beijing for the JavaScript and Node.js community
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- JavaScript and Ruby in ABAP
- Javascript Module pattern template. Shows a class with a constructor and public/private methods/properties. Also shows compatibility with CommonJS(eg Node.JS) and AMD (eg requireJS) as well as in a br
- An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET
- Highlight a Row in GridView without a postback using ASP.NET and JavaScript
- CSS and JavaScript Bundling and Minification in ASP.NET 4.5
- [Javascript] String Padding in Javascript using padStart and padEnd functions
- timer function set and clear out in JavaScript
- JavaScript 学习笔记(七)for(var i in username) {……}、.length、isNaN(……)
- Difference between Properties and Attributes in JavaScript