Mark As Completed Discussion

Variables and Data Types

In C#, variables are used to store and manipulate data. Before using a variable, you need to declare its type and assign a value to it.

C# provides various data types to represent different kinds of information. Some of the commonly used data types are:

  • int (integer): used for storing whole numbers.
  • double (floating-point): used for storing decimal numbers with floating-point precision.
  • string: used for storing text.
  • bool (boolean): used for storing boolean values (true or false).

Here's an example of declaring and initializing variables of different data types:

TEXT/X-CSHARP
1int age = 30;
2string name = "John Doe";
3double salary = 50000.50;
4bool isMarried = false;
TEXT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment