what is string in c# code example

Example 1: how to make a string in c#

string teststring = "";

Example 2: string $ c#

var jh = (firstName: "Jupiter", lastName: "Hammon", born: 1711, published: 1761);
Console.WriteLine($"{jh.firstName} {jh.lastName} was an African American poet born in {jh.born}.");
Console.WriteLine($"He was first published in {jh.published} at the age of {jh.published - jh.born}.");
Console.WriteLine($"He'd be over {Math.Round((2018d - jh.born) / 100d) * 100d} years old today.");

// Output:
// Jupiter Hammon was an African American poet born in 1711.
// He was first published in 1761 at the age of 50.
// He'd be over 300 years old today.

Example 3: c# $ string

string color = blue;

// Both versions do the same thing.
Console.WriteLine("The sky is " + color);
Console.WriteLine($"The sky is {color}");
//Note the dollar ^sign    and ^curly^ brackets.