asa @ ウィキ
http://w.atwiki.jp/asafield/
asa @ ウィキja2009-05-20T12:17:50+09:001242789470csharp-値型と参照型
https://w.atwiki.jp/asafield/pages/43.html
using System;
public class Test
{
public int v;
}
public struct Test2
{
public int v;
}
public class Class1
{
public static int Main(string[] args)
{
Console.WriteLine( DateTime.Now );
int count = 30000000;
Test [] test = new Test[count];
for( int i=0; i<count; i++ )
{
test[i] = new Test();
test[i].v = i;
}
int sum = 0;
for( int i=0; i<count; i++ )
{
sum += test[i].v;
}
Console.WriteLine("sum={0}",sum);
Console.WriteLine( DateTime.Now );
Console.WriteLine("ストラクト");
Console.WriteLine(DateTime.Now);
int count2 = 30000000;
Test2[] test2 = new Test2[count2];
for (int i = 0; i < count; i++)
{
test2[i] = new Test2();
test2[i].v = i;
}
int sum2 = 0;
for (int i = 0; i < count; i++)
{
sum2 += test2[i].v;
}
Console.WriteLine("sum={0}", sum2);
Console.WriteLine(DateTime.Now);
return 0;
} 2009-05-20T12:17:50+09:001242789470csharp-数値型について
https://w.atwiki.jp/asafield/pages/42.html
using System;
public class Class1{
public static int Main(string[] args){
Console.WriteLine("System.SByte {0}, {1}",
System.SByte.MinValue, System.SByte.MaxValue);
Console.WriteLine("System.Byte {0}, {1}",
System.Byte.MinValue, System.Byte.MaxValue);
Console.WriteLine("System.Int16 {0}, {1}",
System.Int16.MinValue, System.Int16.MaxValue);
Console.WriteLine("System.UInt16 {0}, {1}",
System.UInt16.MinValue, System.UInt16.MaxValue);
Console.WriteLine("System.Int32 {0}, {1}",
System.Int32.MinValue, System.Int32.MaxValue);
Console.WriteLine("System.UInt32 {0}, {1}",
System.UInt32.MinValue, System.UInt32.MaxValue);
Console.WriteLine("System.Int64 {0}, {1}",
System.Int64.MinValue, System.Int64.MaxValue);
Console.WriteLine("System.UInt64 {0}, {1}",
System.UInt64.MinValue, System.UInt64.MaxValue);
Consol 2009-05-20T10:45:26+09:001242783926csharp-int型について
https://w.atwiki.jp/asafield/pages/41.html
using System;
public class Class1{
public static int Main(string[] args){
int i=123;
string s = i.ToString();
Console.WriteLine( "i={0}, s={1}", i, s );
System.Int32 i1=123;
System.String s1 = i.ToString();
Console.WriteLine( "i={0}, s={1}", i1, s1);
return 0;
}
} 2009-05-20T10:35:46+09:001242783346csharp-インターフェース
https://w.atwiki.jp/asafield/pages/39.html
using System;
public interface IPerson
{
string getName();
}
public class Taro : IPerson
{
public string getName()
{
return "クラスTaro";
}
}
public class Class1
{
public static int Main(string[] args)
{
// 次の行はコンパイルエラーになる。
// Person person = new Person();//抽象クラスのインスタンスは作成できない
Taro taro = new Taro();
Console.WriteLine( taro.getName() );
IPerson someone = new Taro();
Console.WriteLine( someone.getName() );
return 0;
}
}
2009-05-19T16:12:55+09:001242717175csharp-抽象クラスの継承
https://w.atwiki.jp/asafield/pages/38.html
using System;
public abstract class Person
{
public abstract string getName();
}
public class Taro : Person
{
public override string getName()
{
return "クラスTaro";
}
}
public class Class1
{
public static int Main(string[] args)
{
// 次の行はコンパイルエラーになる。
// Person person = new Person();//抽象クラスのインスタンスは作成できない
Taro taro = new Taro();
Console.WriteLine( taro.getName() );
Person someone = new Taro();
Console.WriteLine( someone.getName() );
return 0;
}
}
2009-05-19T16:02:40+09:001242716560csharp-機能を置き換えて継承
https://w.atwiki.jp/asafield/pages/37.html
using System;
public class Person
{
public string getName()
{
return "Personクラス";
}
public virtual string getName1()
{
return "Personクラス";
}
}
public class Taro : Person
{
public new string getName()
{
return "Taroクラス";
}
public override string getName1()
{
return "Taroクラス";
}
}
public class Class1
{
public static int Main(string[] args)
{
Person person = new Person();
Console.WriteLine(person.getName());
Taro taro = new Taro();
Console.WriteLine(taro.getName());
Person someone = new Taro();
Console.WriteLine( someone.getName() );
Console.WriteLine( someone.getName1() );
return 0;
}
}
2009-05-19T15:19:10+09:001242713950csharp-継承サンプル
https://w.atwiki.jp/asafield/pages/36.html
using System;
public class Person
{
public string getName()
{
return "Personクラス";
}
}
public class Taro : Person
{
public string getTaroName()
{
return "Taroクラス";
}
}
public class Class1
{
public static int Main(string[] args)
{
Person person = new Person();
Console.WriteLine(person.getName());
Taro taro = new Taro();
Console.WriteLine(taro.getName());
Console.WriteLine(taro.getTaroName());
return 0;
}
} 2009-05-19T12:36:36+09:001242704196csharp-インスタンスの作成
https://w.atwiki.jp/asafield/pages/35.html
using System;
class Person
{
public string name;
public int age;
}
class Test
{
static void test()
{
Person person1;//インスタンスへの参照を定義
Person person2;
person1 = new Person();//インスタンス作成
person1.name = "太郎";
person1.age = 20;
person2 = new Person();
person2.name = "花子";
person2.age = 17;
Console.WriteLine(person1.name);
Console.WriteLine(person2.name);
}
public static int Main(string[] args)
{
Test.test();
return 0;
}
} 2009-05-19T12:13:32+09:001242702812csharp-HelloWolld
https://w.atwiki.jp/asafield/pages/34.html
using System;
public class Class1
{
public static int Main(string[] args)
{
Console.WriteLine("Hello Wolld");
return 0;
}
}
2009-05-19T11:56:04+09:001242701764csharp-namespace
https://w.atwiki.jp/asafield/pages/33.html
using System;
namespace Namespace1
{
public class Class1
{
public static void hello()
{
Console.WriteLine("Namespace1のClass1のhello()");
}
public static void test()
{
hello();
Class1.hello();
Namespace1.Class1.hello();
Namespace2.Class1.hello();
}
public static int Main(string[] args)
{
Namespace1.Class1.test();
Namespace2.Class1.test();
return 0;
}
}
}
namespace Namespace2
{
public class Class1
{
public static void hello()
{
Console.WriteLine("Namespace2のClass1のhello()");
}
public static void test()
{
hello();
Class1.hello();
Namespace1.Class1.hello();
Namespace2.Class1.hello();
}
}
} 2009-05-19T11:54:05+09:001242701645