Create a gist now

Instantly share code, notes, and snippets.

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