C#: Variables Cheat Sheet

Integral typessbyte, byte, short, ushort, int, uint, long, ulong, and char
Floating point typesfloat and double
Decimal typesdecimal
Boolean typestrue or false values, as assigned
Nullable typesNullable data types

Defining

<data_type> <variable_list>;

Some valid variable

int i, j, k;
char c, ch;
float f, salary;
double d;

Initializing

variable_name = value;

Example

using System;

namespace VariableDefinition {
   class Program {
      static void Main(string[] args) {
         short a;
         int b ;
         double c;

         /* actual initialization */
         a = 10;
         b = 20;
         c = a + b;
         Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c);
         Console.ReadLine();
      }
   }
}

=> output

a = 10, b = 20, c = 30

Leave a Reply

Your email address will not be published. Required fields are marked *