Skip to content

Instantly share code, notes, and snippets.

View ufcpp's full-sized avatar

Nobuyuki Iwanaga ufcpp

View GitHub Profile
@ufcpp
ufcpp / Program.cs
Created October 7, 2014 13:52
C# vNext in VS 14 CTP 4
using System;
using System.Math;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
@ufcpp
ufcpp / private nameof
Created November 17, 2014 15:23
private nameof
using System;
public class Program
{
public static void Main()
{
// This can be compiled.
// Looks like the compiler translates this "nameof" into the nameof expression on build time.
// However, the language service in Visual Studio interprets it as the private X.nameof method.
var name = nameof(Main);
@ufcpp
ufcpp / csharp6vs2015ctp5
Last active August 29, 2015 14:13
C# 6.0 in VS 2015 CTP5
using static System.Console; // using → using static
class Program
{
static void Main()
{
var x = int.Parse(ReadLine());
WriteLine($"{nameof(x)} = {x}"); // "\{x}" → $"{x}"
}
@ufcpp
ufcpp / ArgListIsTooSlow
Created January 22, 2015 02:55
__arglist is much slower than params array.
using System;
using System.Diagnostics;
public class ArgListIsTooSlow
{
static void Main(string[] args)
{
const int N = 100000;
var sw = new Stopwatch();
@ufcpp
ufcpp / git-alias-u2m.bat
Last active August 29, 2015 14:14
複数のgitリポジトリの一斉更新(upstream → origin)
git config --global alias.u2m '!git fetch upstream; git push origin upstream/master:master -f;'
@ufcpp
ufcpp / ReadonlyField.cs
Created February 1, 2015 07:00
immutable and readonly in C#
class A
{
public int X { get; set; }
}
class B
{
public readonly A A = new A();
}
@ufcpp
ufcpp / ReadonlyStructField.cs
Created February 1, 2015 07:05
readonly struct field
struct Point
{
public int X { get; set; }
public int Y { get; set; }
}
class B
{
public readonly Point P = new Point();
}
@ufcpp
ufcpp / VariableCapture.cs
Created February 1, 2015 08:01
Local variable captured by lambda
using System;
class Program
{
static void Main()
{
var f = X();
Console.WriteLine(f(1)); // 1 (value += 1)
Console.WriteLine(f(2)); // 3 (value += 2)
Console.WriteLine(f(3)); // 6 (value += 3)
@ufcpp
ufcpp / RefParameter.cs
Created February 1, 2015 08:07
Overwriting a ref parameter
using System;
class Point
{
public int X { get; set; }
public int Y { get; set; }
}
class Program
{
@ufcpp
ufcpp / ImmutablePoint.cs
Created February 1, 2015 08:51
Immutable class must have all properties read-only, much annoyed to implement
class Point
{
public int X { get { return _x; } }
private readonly int _x;
public int Y { get { return _y; } }
private readonly int _y;
public Point(int x, int y)
{