This file contains hidden or 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
protected override bool TryGetArray(out ArraySegment<T> segment) | |
{ | |
if (typeof(T) == typeof(byte)) | |
{ | |
return MemoryMarshal.TryGetArray(Unsafe.As<Memory<byte>, Memory<T>>(ref Unsafe.AsRef(in this.memory)), out segment); | |
} | |
else | |
{ | |
segment = default; | |
return false; |
This file contains hidden or 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.Linq.Expressions; | |
using System.Reflection; | |
using System; | |
static class P | |
{ | |
class Foo | |
{ | |
public Guid Value => _value; | |
private readonly Guid _value; |
This file contains hidden or 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 ProtoBuf; | |
using ProtoBuf.Serializers; | |
using System; | |
using System.IO; | |
static class P | |
{ | |
static void Main() | |
{ |
This file contains hidden or 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
const int BLOCK_COUNT = 100000; | |
HashSet<int> uniques = new(BLOCK_COUNT); | |
for (int i = 0; i < 100000; i++) | |
{ | |
if (!uniques.Add(new object().GetHashCode())) | |
Console.WriteLine($"Collision after {uniques.Count} items"); | |
} | |
// I was *expecting* to need the following; turns out that the above *by itself* | |
// usually produces collisions |
This file contains hidden or 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; | |
Console.Write("Please give your age: "); | |
int input = Convert.ToInt32(Console.ReadLine()); | |
if (input < 18) | |
{ | |
Console.WriteLine("Not eligible for voting."); | |
} | |
else |
This file contains hidden or 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 ProtoBuf; | |
using System; | |
static class Program | |
{ | |
static void Main() | |
{ | |
ReadOnlyMemory<byte> bytes = Convert.FromBase64String("CgYI3KzdiQYQidgLGgAgZiokNzk4M2Y0YjAtYjQ3My00NTY1LTkyMWUtMzI5NDk3YjAwMzQy"); | |
var finalValue = Serializer.Deserialize<ileco.chimp.proto.FinalValue>(bytes); | |
Console.WriteLine(finalValue.inputGuid); // 7983f4b0-b473-4565-921e-329497b00342 |
This file contains hidden or 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; | |
using System.Reflection; | |
public class SomeType | |
{ | |
static void Main() => new SomeType().DoTheThing(); | |
public void DoTheThing() | |
{ | |
var prop = GetType().GetProperty(nameof(AgreedInstallationDate)); | |
var value = new DateTime(2021, 08, 17); |
This file contains hidden or 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; | |
using System.Runtime.CompilerServices; | |
using System.Threading; | |
using System.Threading.Tasks; | |
static class P | |
{ | |
static Task Main() => A(); | |
static async Task A() | |
{ |
This file contains hidden or 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; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Xml.Serialization; | |
static class P | |
{ | |
static void Main() | |
{ | |
var xml = @"<ABRPayloadSearchResults xmlns:xsd=""w3.org/2001/XMLSchema"" xmlns:xsi=""w3.org/2001/XMLSchema-instance"" xmlns=""abr.business.gov.au/ABRXMLSearch""> <response> <abnList> <numberOfRecords>2680</numberOfRecords> <abn>95437472757</abn> <abn>38023383928</abn> <abn>12839919648</abn> <abn>50165055391</abn> <abn>60306167177</abn> </abnList> </response> </ABRPayloadSearchResults>"; |
This file contains hidden or 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; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Xml.Serialization; | |
static class P | |
{ | |
static void Main() | |
{ | |
var xml = @"<Response><carList> |