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
32
votes
3 answers

ReferenceError: variable is not defined

I met this issue sometimes but still don't know what causes it. I have this script in the page: $(function(){ var value = "10"; }); But the browser says "ReferenceError: value is not defined". However if I go to the browser console and input…
Andrew Liu
  • 2,478
  • 5
  • 22
  • 29
32
votes
10 answers

How can I write these variables into one line of code in C#?

I am new to C#, literally on page 50, and i am curious as to how to write these variables in one line of code: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace consoleHelloWorld { class Program …
Erik Grosskurth
  • 3,762
  • 5
  • 29
  • 44
32
votes
2 answers

Can I declare the same variable twice in different for loops in JavaScript?

Possible Duplicate: JavaScript Variable Scope I have a JavaScript function for HTML select options for days: // Show and hide days according to the selected year and month. function show_and_hide_days(fp_form) { var select_year=…
Uri
  • 2,992
  • 8
  • 43
  • 86
30
votes
1 answer

Convert "var" to explicit type in Visual Studio?

Possible Duplicate: Tool to refactor C# var to explicit type Does Visual Studio have any type of shortcut (shortcut meaning short of writing out the actual type name) that allows you to write "var" and have it converted to the actual type…
carlbenson
  • 3,177
  • 5
  • 35
  • 54
30
votes
5 answers

Difference between the implementation of var in Javascript and C#

I would like to ask a theoretical question. If I have, for example, the following C# code in Page_load: cars = new carsModel.carsEntities(); var mftQuery = from mft in cars.Manufacturers where mft.StockHeaders.Any(sh=>…
dali1985
  • 3,263
  • 13
  • 49
  • 68
27
votes
5 answers

Var keyword in Java

With Java 10 or +, we can use var keyword for declaration. At initialization, a type is going to be inferred by the compiler. What happens when the class I instantiate and assign to the variable declared with var, is the implementation of the…
Harold Ibouanga
  • 333
  • 1
  • 3
  • 7
27
votes
3 answers

Swift - Lazy Var vs. Let when creating views programmatically (saving memory)

I'm a beginner and I sort of understand Lazy Var vs. Let. I've noticed that it saves a ton of memory usage when using Lazy Var especially with ImageViews. But the tutorials and guides I've seen so far don't use Lazy Var very often, so I'm feeling…
Jazure
  • 461
  • 2
  • 6
  • 15
24
votes
5 answers

Php: what's the difference between $var and &$var?

What is the difference between foreach ($my_array as $my_value) { } And: foreach ($my_array as &$my_value) { } ? May I ask you to give me two real-world examples of when to use one and when you use the other?
Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
24
votes
3 answers

var versus concrete type usage

I have checked 5 or more post in stackoverflow regarding var usage but I am still looking for an answer regarding var usage. I am used to use Concrete type instead of var, but my Resharper complains to change to var. Is var a choice of type - even…
KrishnaDhungana
  • 2,604
  • 4
  • 25
  • 37
23
votes
3 answers

“var” in java 10 and kotlin

I know that we can use the “var” keyword for defining variables in Kotlin: var foo = 3 The latest java update (java 10) also introduces the “var” type: var bar = new int[]{1, 2, 3}; // int[] bar = {1, 2, 3} My question is, what is the difference…
gldanoob
  • 762
  • 1
  • 7
  • 18
22
votes
3 answers

Syntax: Use variable for css value

Trying to keep a box centered vertically within another box. I know there's css that can do this, but I'd rather use jquery, more reliable(?). var textH = $(".Text").height(); var vertAlign = ((140 - textH)/2); $(".Text").css({ marginTop:…
C_K
  • 1,243
  • 4
  • 18
  • 29
21
votes
3 answers

Why is var not deprecated?

Lately after ES6 released, many sources suggested that I use "const" and "let" instead of "var", and that I should stop using "var" in my JavaScript. What I wonder is, if "var" has no advantage over "let" in all points of view, then why didn't they…
Leonard Li
  • 257
  • 1
  • 2
  • 5
21
votes
5 answers

Cannot access Swift var from Objective-C View controller - iOS

I have an app with both Objective-C and Swift based view controllers. I am programatically opening a Swift based view controller from one of my Objective-C based view controllers. The problem I am having is that I can't access the Swift variables…
Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98
20
votes
3 answers

When to use a Var instead of a function?

I am going through the book Web Development with Clojure and it tells me to pass the handler (defined bellow) as a Var object instead of as the function itself, since the function can then change dynamically (this is what wrap-reload does). The…
Maurex
  • 329
  • 1
  • 7
20
votes
4 answers

var won't work with DataGridViewRow

I new to C# and have a question regarding the use of "var" When I use the following code everything works great foreach(DataGridViewRow row in myGrid.Rows) { if (row.Cells[2].Value.ToString().Contains("51000")) { row.Cells[0].Value =…
Joaquin
  • 205
  • 2
  • 5