このページは新人研修用のレジュメです
class A { public A(int x, int y) {} } class B: A { public B(int x, int y): base(x + y, x - y) {} }
myJaggedArray[0] = new int[] {1,3,5,7,9}; myJaggedArray[1] = new int[] {0,2,4,6}; myJaggedArray[2] = new int[] {11,22}; int[][] myJaggedArray = new int [][] { new int[] {1,3,5,7,9}, new int[] {0,2,4,6}, new int[] {11,22} }; int[][] myJaggedArray = { new int[] {1,3,5,7,9}, new int[] {0,2,4,6}, new int[] {11,22} }; int[][,] myJaggedArray = new int [3][,] { new int[,] { {1,3}, {5,7} }, new int[,] { {0,2}, {4,6}, {8,10} }, new int[,] { {11,22}, {99,88}, {0,9} } };
using System; class MainClass { public static void Main() { int odd = 0, even = 0; int[] arr = new int [] {0,1,2,5,7,8,11}; foreach (int i in arr) { if (i%2 == 0) even++; else odd++; } Console.WriteLine("Found {0} Odd Numbers, and {1} Even Numbers.", odd, even) ; } } 出力 Found 4 Odd Numbers, and 3 Even Numbers.
enum HogeType { ALPHA, BETA, GAMMA }; foreach(HogeType type in Enum.GetValues(typeof(HogeType))) { switch(type) { case HogeType.ALPHA: .... };
private int a; int A { get { return a; } set { a = value; } }
using System; class A { int val; public int Val { set { val = value;} get { return val;} } } class As { A[] a_array = new A[3]; public As() { for( int i = 0; i < 3; i++ ) { a_array[i] = new A(); a_array[i].Val = i+1; } } public A this[int i] { get { return a_array[i];} } } /// <summary> /// Class1 の概要の説明です。 /// </summary> class Class1 { /// <summary> /// アプリケーションのメイン エントリ ポイントです。 /// </summary> [STAThread] static void Main(string[] args) { As aaa = new As(); for( int i = 0; i < 3; i++ ) Console.WriteLine(aaa[i].Val); Console.ReadLine(); } }
using System; using c = System.Console; // alias namespace DeleTest { public class cTest { //delegate されるメソッドの実体 public int DelFncImpl( int i ) { c.WriteLine("i=" + i.ToString() ); c.WriteLine("DelFncImpl()呼ばれました"); return i; } public int DelFncImpl2( int i ) { c.WriteLine("i=" + i.ToString() ); c.WriteLine("DelFncImpl2()呼ばれました"); return i; } } public class cStart { public delegate int DelFnc(int i ); public static int Main() { cTest ct = new cTest(); DelFnc[] df = new DelFnc[2]; df[0] = new DelFnc(ct.DelFncImpl); df[1] = new DelFnc(ct.DelFncImpl2); for ( int i = 0; i < 2 ; i++ ) { df[i](i); } return 0; } } }
using System; using c = System.Console; // alias namespace EvntTest { public class Start { delegate void DeleFnc(); static void Handler() { c.WriteLine("hander 呼ばれた"); } static void Handler2() { c.WriteLine("hander2 呼ばれた"); } static void Handler3() { c.WriteLine("hander3 呼ばれた"); } static event DeleFnc TestEvnt; public static void Main() { TestEvnt += new DeleFnc(Handler); TestEvnt += new DeleFnc(Handler2); TestEvnt += new DeleFnc(Handler3); TestEvnt(); } } }
C#の属性を参照
abstract public String Name{get;} abstract public String Name2{get;set;}