Está en la página 1de 6

 Tutorials  Exercises  Services   Sign Up Log in

UERY
 SOBRESALIR XML DJANGO ENTUMECIDO PANDAS NODEJS R

ASP.NET Razor: variables de C#


❮ Anterior Siguiente ❯

Las variables son entidades con nombre que se utilizan para almacenar datos.

Variables
Las variables se utilizan para almacenar datos.

El nombre de una variable debe comenzar con un carácter alfabético y No puede


contener espacios en blanco ni caracteres reservados.

Una variable puede ser de un tipo específico, indicando el tipo de datos que almacena.
Almacén de variables de cadena string ("Bienvenido a W3Schools"), las variables enteras
almacenan valores numéricos (103), las variables de fecha almacenan valores de fecha,
etc.

Las variables se declaran usando la palabra clave var, o usando el tipo (si desea declarar
el tipo), Pero ASP.NET generalmente pueden determinar los tipos de datos
automáticamente.

Ejemplos

// Using the var keyword:


var greeting = "Welcome to W3Schools";
var counter = 103;
var today = DateTime.Today;
// Using
Tutorials Exercises 
data types: Services   Sign Up Log in
string greeting = "Welcome to W3Schools";
UERY
 int SOBRESALIR
counter = 103; XML DJANGO ENTUMECIDO PANDAS NODEJS R
DateTime today = DateTime.Today;

Tipos de datos
A continuación se muestra una lista de tipos de datos comunes:

Type Description Examples

int Integer (whole 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 W3Schools", "John"

Operadores
Un operador ASP.NET dice qué tipo de comando realizar en una expresión.

El lenguaje C# admite muchos operadores. A continuación se muestra una lista de


operadores comunes:

Operator Description Example

= Assigns a value to a variable. i=6

+ Adds a value or variable. i=5+5


- Subtracts a value or variable. i=5-5
* Multiplies a value or variable. i=5*5
/ Divides a value or variable. i=5/5
+=
-=
TutorialsIncrements
 a variable.
Exercises 
Decrements a variable.
Services   i += 1 Up
Sign
i -= 1
Log in

UERY
 SOBRESALIR XML DJANGO ENTUMECIDO PANDAS NODEJS R
== Equality. Returns true if values are equal. if (i==10)

!= Inequality. Returns true if values are not equal. if (i!=10)

< Less than. if (i<10)


> Greater than. if (i>10)
<= Less than or equal. if (i<=10)
>= Greater than or equal. if (i>=10)

+ Adding strings (concatenation). "w3" + "schools"

. Dot. Separate objects and methods. DateTime.Hour

() Parenthesis. Groups values. (i+5)

() Parenthesis. Passes parameters. x=Add(i,5)

[] Brackets. Accesses values in arrays or collections. name[3]

! Not. Reverses true or false. if (!ready)

&& Logical AND. if (ready && clear)


|| Logical OR. if (ready || clear)

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:

Method Description Example


AsInt()
Tutorials Converts
IsInt()
a string
Exercises  toServices
an integer.
 if (myString.IsInt())
 Sign Up
{myInt=myString.AsInt();}
Log in

UERY
 SOBRESALIR XML DJANGO ENTUMECIDO PANDAS NODEJS R
AsFloat() Converts a string to a floating- if (myString.IsFloat())
IsFloat() point number. {myFloat=myString.AsFloat();}

AsDecimal() Converts a string to a decimal if (myString.IsDecimal())


IsDecimal() number.
{myDec=myString.AsDecimal();}

AsDateTime() Converts a string to an ASP.NET myString="10/10/2012";


IsDateTime() DateTime type. myDate=myString.AsDateTime();

AsBool() Converts a string to a Boolean. myString="True";


IsBool() myBool=myString.AsBool();

ToString() Converts any data type to a myInt=1234;


string. myString=myInt.ToString();

❮ Previous Log in to track progress Next ❯

SELECTOR DE COLOR


 Tutorials  Exercises  Services   Sign Up Log in

UERY


SOBRESALIR
SPACES
XML
UPGRADE
DJANGO
AD-FREE
ENTUMECIDO PANDAS NODEJS R

NEWSLETTER GET CERTIFIED

REPORT ERROR

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate

 jQuery Examples
Tutorials  Exercises  Services  XML Certificate
 Sign Up Log in

UERY
 SOBRESALIR XML DJANGO ENTUMECIDO PANDAS NODEJS R

    FORUM ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to
improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of
use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by


W3.CSS.

También podría gustarte