How to declare different types of variables in C#?

C# basic program to declare, assign and print different types of variables: Here, we are writing a C# program, in which we will declare, assign and print different type of values. By IncludeHelp Last updated : April 15, 2023

Declaring Variables

Here, we are declaring 4 different types of variables (char, int, float and string) and assigning them with the appropriate values and then printing the values.

To print values along the message, use the following syntax with Console.Write() or Console.WriteLine():

Console.Write ("Message" + variable_name);
Console.WriteLine("Message" + variable_name);

C# program to declare different types of variables

/*c# basic program to declare different type of variables and
assigning them with the values and then print the values*/

using System;

class HelloWorld {
  static void Main() {
    //declaring different type of variables and
    //assigning them with the values
    char char_value = 'X';
    int int_value = 100;
    float float_value = 10.23f;
    string string_value = "IncludeHelp";

    //printing the values
    Console.WriteLine("char_value = " + char_value);
    Console.WriteLine("int_value = " + int_value);
    Console.WriteLine("float_value = " + float_value);
    Console.WriteLine("string_value = " + string_value);
  }
}

Output

char_value = X
int_value = 100
float_value = 10.23
string_value = IncludeHelp

C# Basic Programs »


Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.