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
public void QuickSort(int[] map, int left, int right) | |
{ | |
do | |
{ | |
// 中略 | |
if (j - left <= right - i) | |
{ | |
if (left < j) QuickSort(map, left, j); | |
left = i; | |
} |
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 Message { } | |
class A : Message { } | |
class B : Message { } | |
class C : Message { } | |
class PatternMatching | |
{ | |
public static void Match(Message m) | |
{ | |
if (m is A) { /* ... */ return; } |
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
abstract class Message | |
{ | |
// コンストラクターを private に | |
private Message() { } | |
// inner クラスであれば private なコンストラクターにアクセスできる | |
// なので、以下の A, B, C はコンパイルできる | |
public sealed class A : Message { } | |
public sealed class B : Message { } | |
public sealed class C : Message { } |
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 Point | |
{ | |
public int X { get; private set; } | |
public int Y { get; private set; } | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="x"><see cref="X"/></param> | |
/// <param name="y"><see cref="Y"/></param> |
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
/// <summary> | |
/// バトル中のアクション。 | |
/// </summary> | |
public abstract class BattleAction | |
{ | |
public abstract void ApplyTo(Unit u); | |
} | |
/// <summary> | |
/// 攻撃アクション。 |
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
public static void ShowBattleAction(BattleAction action) | |
{ | |
var heal = action as Heal; | |
if (heal != null) ShowHeal(heal); | |
var attack = action as Attack; | |
if (attack != null) ShowAttack(attack); | |
} |
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
// C# 5 以前で、きっちり作るなら | |
// プロパティ1つごとに5か所ずつ同じものを書かないと行けない | |
// しかも、プロパティ/フィールド、コンストラクターで結構場所が離れる | |
public class Point | |
{ | |
public int X { get { return _x; } } | |
private readonly int _x; | |
public int Y { get { return _y; } } | |
private readonly int _y; |
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
// composition | |
var expr = Add(Mult(Const(2), X()), Const(1)); | |
// decomposition | |
switch (expr) | |
{ | |
case Add(Mult(var a, var x), var b): ...; | |
} |
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 static System.Console; | |
class Program | |
{ | |
static void Main() | |
{ | |
X(0); // object | |
X(""); // string | |
} |
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 static System.Console; | |
class Program | |
{ | |
static void Main() | |
{ | |
Derived.X(0); // object | |
Derived.X(""); // object。型よりも派生クラス側が優先 | |
Base.X(""); // string | |
} |