String Class

String Class

Example 1: Define a String variable called sitename and assign a text into this variable.

string sitename = "Vitademy";

 

Example 2: Create two string variables and concatenate its values using + (concatenation operator) operator. (Also add a space between two strings)

string hello = "Hello";
string sitename = "Vitademy";
Console.WriteLine(hello+" "+sitename);
//Hello Vitademy

 

Example 3: Join two string variables into one string and print out the merged text all capitalized (uppercase).

string hello = "Hello";
string sitename = "Vitademy";
string mergedText = hello +" "+ sitename;
Console.WriteLine(mergedText.ToUpper());
//HELLO VITADEMY

 

Example 4: Join two string variables into one string and print out the merged text all lowercase.

string hello = "Hello";
string sitename = "Vitademy";
string mergedText = hello +" "+ sitename;
Console.WriteLine(mergedText.ToLower());
//hello vitademy