var keyword in C #

Source: Internet
Author: User
VAR is a 3.5 new type that defines a variable
is actually the definition of the weakening type
VAR can replace any type
The compiler will determine what type you want to use depending on the context.

As to when to use Var i think you can't be sure what type you're going to use.
You can use Var like an OBJECT
But efficiency is higher than object.

The following four characteristics are used when defining variables with Var:

1. Must be initialized at the time of definition. It must be var s = "ABCD" form, not the following form:
var s;
s = "ABCD";

2. Once initialization is complete, it is not possible to assign a value that differs from the initialization value type.

3. The var requirement is a local variable.

4. using var to define variables is different from object, which is exactly the same as defining variables in terms of efficiency and using strongly typed methods.

var keyword in C #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.