What are ASP variables?

A variable is a container used to store data. You can say that a variable is a memory location where data is stored. Suppose there are students with different scores; their scores can be put in a variable.

using System;
public class HelloWorld
{
static void Main()
{
string name = "Hello World";
Console.WriteLine(name);
}
}

At this point, the variable name has been declared. We have a name, and we write it out and print it out. Take a look at another example:

using System;
public class HelloWorld
{
static void Main()
{
int Age = 20;
Console.WriteLine(Age);
}
}

We can declare multiple variables:

using System;
public class HelloWorld
{
static void Main()
{
int x = 50, z = 100;
Console.WriteLine(x);
Console.WriteLine(z);
}
}

Variable naming conventions

  • Variable names cannot start with numbers, reserved characters, or whitespaces – they must start with alphabetic characters.
  • Variable names must be unique and are always case sensitive. They can only contain letters, numbers, and underscore.

We can declare a variable in the first line and then initialize by assigning a value in the following line. We will declare a variable first:

using System;
public class HelloWorld
{
static void Main()
{
int Age;
Age = 36;
Console.WriteLine(Age);
}
}

What is a constant variable?

A constant variable is a variable whose value cannot be changed during program execution. In a constant variable, we cannot assign values at runtime; instead, it must be allocated at compile time.

class HelloWorld
{
static void Main()
{
const int b = 20;
System.Console.WriteLine(b);
}
}

A variable can be of a specific typeindicates the kind of data it stores and have many types.We can use the var keyword or the type to declare the variable, but ASP.NET will automatically determine the data type.For example:

using System;
public class HelloWorld
{
static void Main()
{
char a = 'c';
double temp = 10.68;
bool b = false;
string word = "Hello";
Console.WriteLine(a);
Console.WriteLine(temp);
Console.WriteLine(b);
Console.WriteLine(word);
}
}

ASP Data Types

There are two categories of data types:

  • reference
  • value type

A value type is a data type that stores data within its memory allocation. A reference type is a data type that contains a pointer to another memory allocation that stores the data. Value type variables are stored on the stack, and reference type variables are stored on the heap.

%0 node_1 ASP Data Types node_2 Value Data Types node_1->node_2 node_3 References Data Types node_1->node_3

Free Resources