var

Use of var keyword in C#

After discussion with colleagues regarding the use of the 'var' keyword in C# 3 I wondered what people's opinions were on the appropriate uses of type inference via var? For example I rather lazily used var in questionable circumstances, e.g.:- foreach(var item in someList) { // ... } // Type of 'item' not clear. var something = someOb...

MVC Examples use of var

Maybe I live in a bubble, or am just too new, but I was wondering if anyone else has noticed the heavy use of 'var' to declare variables instead of a specific type in many of the MVC examples by Microsoft? Is there a purpose for this, or is it the "in" thing to do now, or just personal style? Curiously, Jeff ...

C# 'var' vs specific type performance

Earlier I asked a question about why I see so many examples use the 'var' keyword and got the answer that while it's only necessary for anonymous types, that it is used nonetheless to make writing code 'quicker'/easier and 'just because'. Following this link I saw that var gets compiled down to the correct type in the IL (you'll see it ...

In C# when is the var keyword different from typing it out?

C# 3.0 introduced the var keyword. And when compiled, the compiler will insert the right types for you. This means that it will even work on a 2.0 runtime. So far so good. But the other day I found a case where, the var keyword would be replaced with just object and thus not specific enough. Say you have something like: var data = AdoMD...

var for a class in PHP

Hello. I am using a PHP class for login purposes. The MySQL database that the login process checks for the user is defined like this: class flexibleAccess{ var $dbName = 'mydatabase'; However, as I install the application for different people, this $dbName needs constant changes. I have decided to make a config file where I kee...

nullable var using implicit typing in c#?

Is there anyway to have the var be of a nullable type? This implicitly types i as an int, but what if I want a nullable int? var i = 0; Why not support this: var? i = 0; ...

PHPDoc type hinting for array of objects?

So, in PHPDoc one can specify @var above the member variable declaration to hint at its type. Then an IDE, for ex. PHPEd, will know what type of object it's working with and will be able to provide a code insight for that variable. <?php class Test { /** @var SomeObj */ private $someObjInstance; } ?> This works great unt...

LINQ2SQL: How do I declare a member variable of type var?

I have a class like this public class foo { private void getThread() { var AllThreads = from sc in db.ScreenCycles join s in db.Screens on sc.ScreenID equals s.ScreenID select s; } } I want to make the AllThreads variable a class variable...

In C# 3.0 we use "var" what is its alternative in C# 2.0?

I am learning plug able architecture in .Net using Managed Extensibility Framework (MEF.) I saw sample code on the net, but when I tried to implement it I got stuck at one point. The code was using: var catalog = new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly()); var container = new CompositionContainer(catalog.Creat...

Generic var c++

Hello, I want to create a generic var, that could be from one class or another class. In this code sample I want that var aa be generic so in my code I can access code from class A or class B. But aa MUST BE GLOBAL. Could you help me? class MyClass { public: MyClass() {} //contructor padrão, não deve ser utilizado isoladamente ...

var keyword in C# 3.0

Possible Duplicate: Whats the point of the var keyword? Hello everyone, I want to confirm whether my understanding is correct. If I do not use LINQ, then the only benefit of using var is to make brevity? Is that correct understanding? thanks in advance, George ...

variables hell - problem with vars and tabs (firefox extension)

I try to make firefox extension, that display two buttons: 1 and 2. When you press button1 to var path get value, that is address of current open page, then new tab is opening becoming active. In this tab there is button2, that allow to put (innerHTML) value of var path (this address of first tab). And now the problem: button1 uses funct...

C# - var to List<T> conversion

How to cast/convert a var type to a List type? This code snippet is giving me error: List<Student> studentCollection = Student.Get(); var selected = from s in studentCollection select s; List<Student> selectedCollection = (List<Student>)selected; foreach (Student s in selectedCollection) { s.Show(); } ...

Are implicitly-typed variables the way forward (C#)

I am using StyleCop for Resharper on a project originally written for .net v2. But I've since upgraded this project for 3.5 framework. Stylecop is recommending I change the bulk of my explicitly typed variables to implicitly typed for example: string - var custom strong type - var Is this the way forward when working with a .net 3....

Is there any technical reason to use or not to use var in C# when the type is known?

It seems that more and more C# code I read uses the var type identifier: foreach (var itemChange in ItemChanges) { //... } instead of explicitly stating the type: foreach (ItemChange itemChange in ItemChanges) { //... } even when the type is known. I am still using the latter explicit version just because I think someone r...

Using var outside of a method

I wanted to use the var keyword to declare a field in my class however var only seems to work inside methods. The code I have looks like: public static Dictionary<string, string> CommandList = new Dictionary<string, string>{}; and I wanted to have: public static var CommandList = new Dictionary<string, string> How come this isn't ...

JavaScript variable scope question: to var, or not to var

Hi All, Many thanks in advance. I'm working out of a schoolbook and they're using one function to call another which opens a window: function rtest(){ content='dans window'; oneWindow=open("","Window 1","width=450,height=290"); newWindow(oneWindow); } function newWindow(x){ x.document.close(); x.document.open(); x.do...

i need to pass url var in the scr of a iframe

i need to know how to pass everything after the .php part in this link "http://wreckedclothing.net/help/[email protected]&amp;t=985559" to a iframe on the same page. "hosted on the same site" like this "<iframe> src="http://www.wreckedclothing.net/[email protected]&amp;t=985559" fram...

escape caracter

i have thi function : <?php function getmypost($number) { query_posts('p=1828'); while (have_posts()) : the_post(); the_title('<h1>', '</h1>'); the_content(); endwhile; } ?> i need to make the 1828 as a variable i have try : query_posts('\'p='. $number .'\''); it does not work.....

How much impact does use of 'var' have on performance of C# Compiler?

I find the var keyword greatly helps in reducing noise in my C# code, with little loss of readability; I'd say that I now use explicit typing only when the compiler forces me to. I know that using var does not change the runtime characteristics of my code. But the question has just occurred to me: am I paying a big penalty at compile ti...