Skip to content

Instantly share code, notes, and snippets.

@jmreynolds
Last active February 2, 2016 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmreynolds/cf1e483aa9d25dc76196 to your computer and use it in GitHub Desktop.
Save jmreynolds/cf1e483aa9d25dc76196 to your computer and use it in GitHub Desktop.
C# 6 Features: String Interpolation
public class Person
{
public Person()
{
PersonId = Guid.NewGuid();
}
public Guid PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public static void Main()
{
var person = new Person();
person.FirstName = "Joe";
person.LastName = "Reynolds";
var outputStr = "Person ID: " + person.PersonId + Environment.NewLine +
"Name: " + person.FirstName + " " + person.LastName;
Console.WriteLine(outputStr);
}
using System;
public class Program
{
public static void Main()
{
var person = new Person();
person.FirstName = "Joe";
person.LastName = "Reynolds";
Console.WriteLine($"New Person ID: {person.PersonId}");
Console.WriteLine($"New Name: {person.FirstName} {person.LastName}");
Console.WriteLine("Did it work?");
}
}
using System;
public class Program
{
public static void Main()
{
var person = new Person();
person.FirstName = "Joe";
person.LastName = "Reynolds";
Console.WriteLine(string.Format("Person ID: {0}", person.PersonId.ToString()));
Console.WriteLine(string.Format("Name: {0} {1}", person.FirstName, person.LastName));
Console.WriteLine("Did it work?");
}
}
static void Main(string[] args)
{
string name = "Stranger";
Console.WriteLine($"Howdy {name}");
Console.ReadKey();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment