Home
Aptitude
Categories


Home » C# programs » C# basic programs

C# | Declare different types of variables, assign the values and print



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.
Submitted by IncludeHelp, on December 04, 2018

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); 

Program:

/*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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.