2015-09-01から1ヶ月間の記事一覧

Mono: コンパイラオプションでシンボルを定義する

mcs コマンドの -define オプションでシンボルを定義することが出来ます。 // define.cs using System; class Program { static void Main() { #if DEBUG Console.WriteLine("DEBUG シンボルは、定義されています"); #else Console.WriteLine("DEBUG シンボ…

文字列を置換する。置換回数を指定する

string クラスの Replace メソッドによる文字列の置換は、マッチする全ての文字列が置換されます。 $ csharp Mono C# Shell, type "help;" for help Enter statements below. csharp> var s = "abc abc abc"; csharp> s.Replace("abc", "def"); "def def def…

文字列の反転

文字列を反転させるプログラムです。 using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string s = "hello"; var t = s.Reverse(); // Iterator が返されます Console.WriteLine(t); string s2 = …

2次元配列の回転

2 次元配列を、時計回り、反時計回りに回転させるプログラムです。 実行例です。 時計回りに回転 0 1 2 3 4 5 3 0 4 1 5 2 5 4 3 2 1 0 2 5 1 4 0 3 反時計回りに回転 0 1 2 3 4 5 2 5 1 4 0 3 5 4 3 2 1 0 3 0 4 1 5 2 プログラム using System; using Syst…