ASP.NET Razor - C# Variables

Posted Chuck Lu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ASP.NET Razor - C# Variables相关的知识,希望对你有一定的参考价值。

http://www.w3schools.com/aspnet/razor_cs_variables.asp

Variables are named entities used to store data.

 

Converting Data Types

Converting from one data type to another is sometimes useful.

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

As a rule, user input comes as strings, even if the user entered a number. Therefore, numeric input values must be converted to numbers before they can be used in calculations.

Below is a list of common conversion methods:

MethodDescriptionExample
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()
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 data type to a string. myInt=1234;
myString=myInt.ToString();

以上是关于ASP.NET Razor - C# Variables的主要内容,如果未能解决你的问题,请参考以下文章

C# ASP.NET RAZOR 链接SQLSERVER

ASP.NET Razor - C# 变量

ASP.NET Razor - C# 逻辑条件

ASP.NET Web Pages - 添加 Razor 代码

ASP.NET C# 倒计时到报价结束 - Razor 视图

在 ASP.NET C# 和 Razor 中的变量内编写 HTML 代码