Detailed analysis ASP.NET The C # variable of razor



Variables are used to store data.

The name of a variable must start with an alphabetic character and cannot contain spaces or reserved characters.

A variable can be of a specified type, representing the type of data it stores. The string variable stores the string value (“welcome to” RUNOOB.COM “), integer variable stores numeric value (103), date variable stores date value, and so on.

Variables are declared with the VaR keyword, or by using a type (if you want to declare a type), but ASP.NET Usually, the data type can be determined automatically.

// Using the var keyword:
var greeting = "Welcome to RUNOOB.COM";
var counter = 103;
var today = DateTime.Today;

// Using data types:
string greeting = "Welcome to RUNOOB.COM";
int counter = 103;
DateTime today = DateTime.Today;

data type

The common data types are listed below:

type describe example
int Integer (all digits) 103, 12, 5168
float Floating point number 3.14, 3.4e38
decimal Decimal digit (high precision) 1037.196543
bool Boolean value true, false
string character string “Hello RUNOOB.COM”, “John”


Operator tell ASP.NET What kind of command to execute in an expression.

C # language supports multiple operators. The common operators are listed below:

operator describe example
= Assign a value to a variable. i=6

Add a value or a variable.
Subtract a value or a variable.
Multiply by a value or a variable.
Divide by a value or a variable.
Variable increment.
Variable decrement.
i += 1
i -= 1
== equal. Returns true if the values are equal. if (i==10)
!= It doesn’t wait. Returns true if the values are not equal. if (i!=10)
Less than.
Greater than.
Less than or equal to.
Greater than or equal to.
if (i<10)
if (i>10)
if (i<=10)
if (i>=10)
+ A connection string (a series of interrelated things). “run” + “oob”
. Point number. Separate objects and methods. DateTime.Hour
() Parentheses. Group values. (i+5)
() Parentheses. Pass parameters. x=Add(i,5)
[] Brackets. Access the values of an array or collection. name[3]
! No. True / false negation. if (!ready)
Logic and logic.
Logical or.
if (ready && clear)
if (ready || clear)

shifting clause

It’s sometimes useful to switch from one data type to another.

The most common example is converting a string input to another type, such as an integer or a date.

Under the general rules, the user input is treated as a string, even if the user has entered a number. Therefore, the numerical input must be converted to a number before it can be used for calculation.

The common conversion methods are listed as follows:

method describe example
Converts a string to an integer. if (myString.IsInt())
Converts a string to a floating-point number. if (myString.IsFloat())
Converts a string to a decimal number. if (myString.IsDecimal())
Convert string to ASP.NET Datetime type. myString=”10/10/2012″;
Converts a string to a Boolean value. myString=”True”;
ToString() Converts any data type to a string. myInt=1234;

The above is a detailed analysis ASP.NET More about the C # variable of razor ASP.NET For information about the C # variable of razor, please pay attention to other related articles of developer!

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]