02. C# Fundamentals: Strings

Strings are ideally anything that contains quotations around them. We can read Input from the users as Strings, or we can display the string output value to users as well. Let’s continue where we left off from the last articles except Modify the code just a little bit. within the main function of your code delete the print statement and add a string variable with your name, an example is listed below, replace the content in the quotation marks with your actual name:

string Name = "Insert Your Name here";

From here, we can print out the name assigned as such:

using System;

class MainClass {
  public static void Main (string[] args) {
    string Name = "Batman"; 
    Console.WriteLine(Name);
  }
}

The output should look something like such if I assigned the value of Batman to the string Name :

> Batman

We can also take this a step further and concatenate our output with another string using the + symbol listed below:

Console.WriteLine("Hello! " + Name);

The output for the following should be as such:

> Hello! Batman

Similarly we can also concatenate strings and store them within a variable as such:

string Name = "Batman"; 
string MyName = "Adam"; 
string Message = "Hello " + Name + " My Name is " + MyName; 
Console.WriteLine(Message); 

Your overall code should look as such:

using System;

class MainClass {
  public static void Main (string[] args) {
    string Name = "Batman"; 
    string MyName = "Adam"; 
    string Message = "Hello " + Name + ", " + " My Name is " + MyName; 
    Console.WriteLine(Message); 
  }
}

The output should display as such:

> Hello Batman, My Name is Adam

These are just a few examples of concatenating string and printing them into the console. Feel free to play around with string concatenation by creating new variables and using the + operator to concatenate strings.