WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

ASP.NET Razor - C# Variables


Variables are named substances used to store data.


Variables

Variables are utilized to store data.

The name of a variable must start with an alphabetic character and can't contain whitespace or held characters.

A variable can be of a explicit sort, showing the sort of information it stores. String factors store string esteems ("Welcome to welookups"), whole number factors store number qualities (103), date factors store date esteems, etc.

Variables are pronounced utilizing the var watchword, or by utilizing the sort (in the event that you need to pronounce the sort), yet, ASP.NET can more often than not decide information types automatically.

Examples

/ Utilizing the var keyword:
var welcoming = "Welcome to welookups";
var counter = 103;
var today = DateTime.Today;

//Using information types:
string welcoming = "Welcome to welookups";
int counter = 103;
DateTime today = DateTime.Today;

Data Types

Below is a rundown of  regular information types:

Type Description Examples
int Integer (entire numbers) 103, 12, 5168
float Floating-point number 3.14, 3.4e38
decimal Decimal number (higher precision) 1037.196543
bool Boolean true, false
string String "Hello welookups", "John"

Operators

An administrator reveals to ASP.NET what sort of order to perform in an expression.

 The C# language underpins numerous administrators. The following is a rundown of common operators:

Operator Description Example
= Assigns an incentive to a variable. i=6
+
-
*
/
Adds an esteem or variable.
Subtracts an esteem or variable.
Multiplies a esteem or variable.
Divides an esteem or variable.
i=5+5
i=5-5
i=5*5
i=5/5
+=
-=
Increments a variable.
Decrements a variable.
i += 1
i - = 1
== Equality. Returns genuine if values are equal. if (i==10)
!= Inequality. Returns genuine if values are not equal. if (i!=10)
<
>
<=
>=
Less than.
Greater than.
Less than or equal.
Greater than or equal.
if (i<10)
if (i>10)
if (i<=10)
if (i>=10)
+ Adding strings (concatenation). "w3" + "schools"
. Dot. Separate items and methods. DateTime.Hour
() Parenthesis. Gatherings values. (i+5)
() Parenthesis. Passes parameters. x=Add(i,5)
[] Brackets. Gets to values in clusters or collections. name[3]
! Not. Turns around evident or false. if (!ready)
&&
||
Logical AND.
Logical OR.
if (prepared && clear)
if (prepared || clear)

Converting Data Types

Converting starting with one information type then onto the next is here and there useful.

The most regular precedent is to change over string contribution to another kind, for example, a number or a date.

As a standard, client input comes as strings, regardless of whether the client entered a number. Hence, numeric information esteems must be changed over to numbers before they can be utilized in calculations.

Below is a rundown of common transformation methods:

Method Description Example
AsInt()
IsInt()
Converts a string to an integer. if (myString.IsInt())
  {myInt=myString.AsInt();}
AsFloat()
IsFloat()
Converts a string to a skimming 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()
Converts a string to an ASP.NET DateTime type. myString="10/10/2012";
myDate=myString.AsDateTime();
AsBool()
IsBool()
Converts a string to a Boolean. myString="True";
myBool=myString.AsBool();
ToString() Converts any information type to a string. myInt=1234;
myString=myInt.ToString();