Detailed analysis ASP.NET The C # variable of razor

Time:2021-3-9

variable

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

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.
i=5+5
i=5-5
i=5*5
i=5/5
+=
-=
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
AsInt()
IsInt()
Converts a string to an integer. if (myString.IsInt())
{myInt=myString.AsInt();}
AsFloat()
IsFloat()
Converts a string to a floating-point number. if (myString.IsFloat())
{myFloat=myString.AsFloat();}
AsDecimal()
IsDecimal()
Converts a string to a decimal number. if (myString.IsDecimal())
{myDec=myString.AsDecimal();}
AsDateTime()
IsDateTime()
Convert string to ASP.NET Datetime type. myString=”10/10/2012″;
myDate=myString.AsDateTime();
AsBool()
IsBool()
Converts a string to a Boolean value. myString=”True”;
myBool=myString.AsBool();
ToString() Converts any data type to a string. myInt=1234;
myString=myInt.ToString();

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 […]