Skip to content

Instantly share code, notes, and snippets.

@RickStrahl
Created December 27, 2016 11:22
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save RickStrahl/ef851ce1597b97ee0c2dba06a858db07 to your computer and use it in GitHub Desktop.
LinqPad Sample Code for CSharp String Interpolation
void Main()
{
var msg = $".NET Version: {Environment.Version.ToString()}";
msg.Dump();
StringFormat();
BasicInterpolation();
MultiLine();
Log(new Exception("Test Exception"));
}
public void StringFormat()
{
string name = "Rick";
int accesses = 10;
string output = string.Format("{0}, you've been here {1:n0} times.", name, accesses);
output.Dump();
}
public void BasicInterpolation()
{
string name = "Rick";
int accesses = 10;
string output = $"{name}, you've been here {accesses:n0} times.";
output.Dump();
}
public void MultiLine()
{
// parameterized values
DateTime releaseDate = DateTime.Now.Date;
decimal version = 1.01M;
string newStuff = @"
* Fixed blah
* Updated foo
* Refactored stuff
";
string message = $@"Version {version} of Markdown Monster is now available.
Released on: {releaseDate:d}
{newStuff}
";
message.Dump();
}
public void Log(Exception ex)
{
string val = $"{DateTime.UtcNow.ToString("dd-MM-yyyy HH:mm:ss")} - DOM Doccument update failed: {ex.Message}";
val.Dump();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment