Skip to content

Instantly share code, notes, and snippets.

View svick's full-sized avatar

Petr Onderka svick

View GitHub Profile
@svick
svick / Program.cs
Created August 22, 2014 22:48
C# 6.0 primary constructor accessibility
class Program
{
static void Main()
{
new PublicConstructor(""); // OK
new PrivateConstructor(""); // error CS0122: 'Program.PrivateConstructor.PrivateConstructor(string)' is inaccessible due to its protection level
new PrimaryConstructor(""); // OK
}
private class PrimaryConstructor(string firstName)
@svick
svick / Program.cs
Last active August 29, 2015 14:08
Proving that the Task dispatching loop doesn't wait for thread scheduling quantum
using System;
using System.Diagnostics;
using System.Threading.Tasks;
class Program
{
private static void Main()
{
MainAsync().Wait();
}
@svick
svick / any.cpp
Last active August 29, 2015 14:10
Any
any_of(list.begin(), list.end(), [](SomeType x){ return predicate(x); })
@svick
svick / TimeUnits.cs
Last active August 29, 2015 14:10
C# 6.0 simple time units
using System;
using TimeUnits;
public static class Program
{
public void Main()
{
Console.WriteLine(70.5 * s);
}
}
@svick
svick / Action.il
Created February 7, 2015 23:59
Delegate with static member
.assembly ActionTest {}
.assembly extern mscorlib
{
.ver 4:0:0:0
.publickeytoken = (B7 7A 5C 56 19 34 E0 89)
}
.namespace Test
{
using System;
static class Program
{
private static void Main()
{
Intermediary<C>();
Console.WriteLine();
Intermediary<S>();
}
@svick
svick / gist:8c2696222800aa031450
Last active August 29, 2015 14:20
It's not safe to call ToList on IsReadOnly collection
var cdict = new ConcurrentDictionary<int, int>();
var t = Task.Run(() => {
for (int i = 0; i < 100000; i++)
cdict[i] = i;
});
IEnumerable<KeyValuePair<int, int>> kvps = new ReadOnlyDictionary<int, int>(cdict);
((ICollection<KeyValuePair<int, int>>)kvps).IsReadOnly.Dump(); // true
@svick
svick / Program.cs
Created May 13, 2015 23:08
Incorrect compiler error for method with async/non-async delegate overloads
using System;
using System.Threading.Tasks;
class Program
{
static void M(Func<Task<int>> f, int i)
{ }
static void M(Func<int> f, int i)
{ }
@svick
svick / ico.cs
Created February 11, 2011 13:25
using System;
using System.Net;
using System.Xml;
using System.Linq;
public class Test
{
public static void Main()
{
Console.Write("ICO: ");
@svick
svick / AnotherContinent.cs
Created May 31, 2011 19:10
Mock of how could you call a method on another computer using DynamicProxy and pseudo-JSON
using System;
using System.Linq;
using Castle.DynamicProxy;
namespace AnotherContinent
{
class Program
{
static void Main()
{