Skip to content

Instantly share code, notes, and snippets.

@jmreynolds
Forked from svick/Program.cs
Last active February 2, 2016 00:21
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/2dce22c415eb824c2ded to your computer and use it in GitHub Desktop.
Save jmreynolds/2dce22c415eb824c2ded to your computer and use it in GitHub Desktop.
C# 6.0 Features: FormattableString on .Net 4.0
using System;
using System.Globalization;
static class Program
{
private static void Main()
{
double d = 3.14;
IFormattable s = $"{d}";
Console.WriteLine(s.ToString(null, CultureInfo.GetCultureInfo("cs-cz")));
Console.WriteLine(s.ToString(null, CultureInfo.InvariantCulture));
}
}
namespace System.Runtime.CompilerServices
{
static class FormattableStringFactory
{
public static FormattableString Create(string s, params object[] args)
{
return new FormattableString(s, args);
}
}
class FormattableString : IFormattable
{
private readonly string s;
private readonly object[] args;
public FormattableString(string s, object[] args)
{
this.s = s;
this.args = args;
}
public string ToString(string ignored, IFormatProvider formatProvider)
{
return string.Format(formatProvider, s, args);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment