Created
December 27, 2016 11:22
-
-
Save RickStrahl/ef851ce1597b97ee0c2dba06a858db07 to your computer and use it in GitHub Desktop.
LinqPad Sample Code for CSharp String Interpolation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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