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
class Program | |
{ | |
static void X(bool x) { } | |
static void X(bool x, bool y) { } | |
static bool A<T1, T2>(int x) => true; | |
class B { } | |
class C { } | |
static void Main() | |
{ |
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
using System.Globalization; | |
using System.Runtime.CompilerServices; | |
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; | |
static string m(bool condition) => string.Create( | |
CultureInfo.GetCultureInfo("fr-fr"), | |
$"direct: {1.5} or {1:c}, nested: {If(condition, $"{1.5}", $"{1:C}")}"); | |
Console.WriteLine(m(true)); |
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
using System.Buffers; | |
public interface IDefaultSpanFormattable : ISpanFormattable | |
{ | |
string IFormattable.ToString(string? format, IFormatProvider? formatProvider) | |
{ | |
var buffer = (stackalloc char[512]); | |
if (TryFormat(buffer, out var charsWritten, format, formatProvider)) | |
{ | |
return new string(buffer[..charsWritten]); |
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
using System.Diagnostics.CodeAnalysis; | |
using System.Runtime.CompilerServices; | |
var nodes = new Node<string>[] | |
{ | |
new("a0", 2), | |
new("a1", 5), | |
new("a2", 1), | |
new("a3", -2), | |
new("a4", 3), |
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
using System.Text.RegularExpressions; | |
using System.Windows; | |
class Program | |
{ | |
[STAThread] | |
static void Main() | |
{ | |
var x = Clipboard.GetText(); |
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
using System.Globalization; | |
var items = new[] | |
{ | |
"ABc", | |
"Abc", | |
@"A\c", | |
}; | |
// ASCII コード順。 |
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
var a = new[] { | |
0, | |
1, | |
2, | |
3, | |
4, | |
5, | |
6, | |
7, | |
8, |
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
// see https://stackoverflow.com/questions/6643076/tarjan-cycle-detection-help-c-sharp | |
// tests simple model presented on https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm | |
using System.Runtime.InteropServices; | |
var cycles = CycleDetector.Detect( | |
(1, 2), | |
(2, 3), | |
(3, 1), | |
(4, 3), | |
(4, 5), |
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
// Unicode 8.0 | |
int ᏸ = 8; // U+13F8, Cherokee Small Letter Ye | |
// Unicode 9.0 | |
int Ɪ = 9; // U+A7AE, Small Captital I | |
// Unicode 10.0 | |
int ৼ = 10; // U+09FC, Bengali Letter Vedic Anusvara | |
// Unicode 11.0 |
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
Console.WriteLine("123".ParseOrNull<int>()); | |
Console.WriteLine("1a3".ParseOrNull<int>()); | |
static class Ex | |
{ | |
public static T? ParseOrNull<T>(this string? s, IFormatProvider? provider = null) | |
where T : struct, IParsable<T> | |
=> T.TryParse(s, provider, out var value) ? value : null; | |
} |