Questions tagged [var]

var is a keyword in a number of programming languages.

In computer programming, a variable or scalar is a storage location paired with an associated symbolic name (an identifier), which contains some known or unknown quantity of information referred to as a value.

The variable statement declares a variable, optionally initializing it to a value.

In C# it is used to declare a variable of an implied type.

Beginning in Visual C# 3.0, variables that are declared at method scope can have an implicit type var. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type. The following two declarations of i are functionally equivalent:

 var i = 10; // implicitly typed
 int i = 10; //explicitly typed

References:

2462 questions
6164
votes
40 answers

What is the difference between "let" and "var"?

ECMAScript 6 introduced the let statement. I've heard that it's described as a local variable, but I'm still not quite sure how it behaves differently than the var keyword. What are the differences? When should let be used instead of var?
TM.
  • 108,298
  • 33
  • 122
  • 127
2199
votes
27 answers

What is the scope of variables in JavaScript?

What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally?
lYriCAlsSH
  • 57,436
  • 10
  • 26
  • 20
455
votes
15 answers

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.
Artem Russakovskii
  • 21,516
  • 18
  • 92
  • 115
405
votes
86 answers

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,…
ljs
  • 37,275
  • 36
  • 106
  • 124
283
votes
15 answers

What is the equivalent of the C# 'var' keyword in Java?

One use of the var keyword in C# is implicit type declaration. What is the Java equivalent syntax for var?
Arturo
  • 3,066
  • 2
  • 18
  • 11
244
votes
12 answers

Will using 'var' affect performance?

Earlier I asked a question about why I see so many examples use the varkeyword and got the answer that while it is only necessary for anonymous types, that it is used nonetheless to make writing code 'quicker'/easier and 'just because'. Following…
Jeff Keslinke
  • 4,278
  • 5
  • 30
  • 49
231
votes
23 answers

Why does ReSharper want to use 'var' for everything?

I've just started using ReSharper with Visual Studio (after the many recommendations on SO). To try it out I opened up a recent ASP.NET MVC project. One of the first and most frequent things I've noticed it suggesting is to change most/all my…
Chris
  • 6,568
  • 3
  • 22
  • 21
179
votes
4 answers

Why should I use var instead of a type?

Possible Duplicate: ReSharper and var After I have installed ReSharper it demands(by warnings) that I use var whenever possible, for example UnhandledExceptionEventArgs ue = (UnhandledExceptionEventArgs) t; ReSharper wants to turn it into var ue…
IAdapter
  • 62,595
  • 73
  • 179
  • 242
154
votes
4 answers

VB.NET equivalent to C# var keyword

Is there a VB.NET equivalent to the C# var keyword? I would like to use it to retrieve the result of a LINQ query.
Jack
  • 1,549
  • 2
  • 9
  • 3
120
votes
5 answers

Clojure differences between Ref, Var, Agent, Atom, with examples

I'm very new to Clojure, Can you guys give me explanation with real world scenarios. I mean, where to use Ref, Var, Agent, Atom. I read book, but, still couldn't understand the real world examples.
user472557
116
votes
15 answers

Difference between "var" and "dynamic" type in Dart?

According to this article: As you might know, dynamic (as it is now called) is the stand-in type when a static type annotation is not provided. So, what is the difference between dynamic and var? When to use?
Gero
  • 12,993
  • 25
  • 65
  • 106
93
votes
5 answers

golang append() evaluated but not used

func main(){ var array [10]int sliceA := array[0:5] append(sliceA, 4) fmt.Println(sliceA) } Error : append(sliceA, 4) evaluated but not used I don't Know why? The slice append operation is not run...
L.jerson
  • 933
  • 1
  • 6
  • 6
92
votes
3 answers

switch with var/null strange behavior

Given the following code: string someString = null; switch (someString) { case string s: Console.WriteLine("string s"); break; case var o: Console.WriteLine("var o"); break; default: …
budi
  • 6,351
  • 10
  • 55
  • 80
83
votes
2 answers

Why let and var bindings behave differently using setTimeout function?

This code logs 6, 6 times: (function timer() { for (var i=0; i<=5; i++) { setTimeout(function clog() {console.log(i)}, i*1000); } })(); But this code... (function timer() { for (let i=0; i<=5; i++) { setTimeout(function clog()…
user2290820
  • 2,709
  • 5
  • 34
  • 62
69
votes
3 answers

Volatile properties in Kotlin?

How does one mark a var in Kotlin volatile? volatile public var tmpEndedAt: Long? = null gives me the error: "unresolved reference: volatile"
Andrew Cholakian
  • 4,392
  • 3
  • 26
  • 27
1
2 3
99 100