public static void main(string [] args) { MyInteger [] a = new MyInteger[NUM_ITEMS]; for (int i = 0; i < a.Length; i++) { a[i] = new MyInteger(i); } for (theSeed = 0; theSeed < 20; theSeed++) { Random.permute(a); Sort.insertionSort(a); checkSort(a); Random.permute(a); Sort.heapsort(a); checkSort(a); Random.permute(a); Sort.shellsort(a); checkSort(a); Random.permute(a); Sort.mergeSort(a); checkSort(a); Random.permute(a); Sort.quicksort(a); checkSort(a); Random.permute(a); Sort.quickSelect(a, NUM_ITEMS / 2); System.Console.WriteLine(a[NUM_ITEMS / 2 - 1].intValue() + " " + NUM_ITEMS / 2); } }
/// <summary> /// Returns the hashcode of this Object /// </summary> /// <returns>Hash code (int)</returns> public override int GetHashCode() { // Credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { int hash = 41; // Suitable nullity checks etc, of course :) if (Id != null) { hash = hash * 59 + Id.GetHashCode(); } if (Name != null) { hash = hash * 59 + Name.GetHashCode(); } if (Description != null) { hash = hash * 59 + Description.GetHashCode(); } if (MyBoolean != null) { hash = hash * 59 + MyBoolean.GetHashCode(); } if (MyCreditCard != null) { hash = hash * 59 + MyCreditCard.GetHashCode(); } if (MyCurrency != null) { hash = hash * 59 + MyCurrency.GetHashCode(); } if (MyDateTime != null) { hash = hash * 59 + MyDateTime.GetHashCode(); } if (MyDouble != null) { hash = hash * 59 + MyDouble.GetHashCode(); } if (MyEmail != null) { hash = hash * 59 + MyEmail.GetHashCode(); } if (MyFloat != null) { hash = hash * 59 + MyFloat.GetHashCode(); } if (MyImageUrl != null) { hash = hash * 59 + MyImageUrl.GetHashCode(); } if (MyInteger != null) { hash = hash * 59 + MyInteger.GetHashCode(); } if (MyLong != null) { hash = hash * 59 + MyLong.GetHashCode(); } if (MyPhone != null) { hash = hash * 59 + MyPhone.GetHashCode(); } if (MyPostalCode != null) { hash = hash * 59 + MyPostalCode.GetHashCode(); } if (MyString != null) { hash = hash * 59 + MyString.GetHashCode(); } if (MyTextArea != null) { hash = hash * 59 + MyTextArea.GetHashCode(); } if (MyTicks != null) { hash = hash * 59 + MyTicks.GetHashCode(); } if (MyUrl != null) { hash = hash * 59 + MyUrl.GetHashCode(); } if (Comments != null) { hash = hash * 59 + Comments.GetHashCode(); } if (AuditEntered != null) { hash = hash * 59 + AuditEntered.GetHashCode(); } if (AuditEnteredBy != null) { hash = hash * 59 + AuditEnteredBy.GetHashCode(); } if (AuditUpdated != null) { hash = hash * 59 + AuditUpdated.GetHashCode(); } if (AuditUpdatedBy != null) { hash = hash * 59 + AuditUpdatedBy.GetHashCode(); } return(hash); } }
public override QSResult Execute(ref QSData data) { int counter = 0; IList <QuadraticPair> pairs = data.BSmooth; bool foundquadratic = false; ControlHandler.SetPropertyValue( m_lblInfo, "Text", string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_smooth, pairs.Count)); // // Suche nach glatten Werten, die selbst schon Quadrat sind // foreach (QuadraticPair pair in pairs) { String msg; if (data.IsIgnored(PrimesBigInteger.ValueOf(pair.B))) { pair.QuadraticStatus = QuadraticStatus.Ignore; } if (pair.QuadraticStatus == QuadraticStatus.Ignore) { msg = String.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_ignored, pair.B); } else { int sqrt = (int)Math.Sqrt(pair.B); if (sqrt * sqrt == pair.B) { foundquadratic = true; pair.QuadraticStatus = QuadraticStatus.Quadratic; msg = String.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_issquare, pair.B, pair.B, sqrt); } else { msg = String.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_isnotsquare, pair.B); } } ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, msg.ToString(), counter++, 0, 0, 0 }); if (foundquadratic) { return(QSResult.Ok); } } // // Suche nach Produkten von glatten Werten, die ein Quadrat ergeben // int pslen = (int)Math.Pow(2, pairs.Count); for (int i = 1; i < pslen; i++) { MyInteger mi = new MyInteger(i); if (mi.BitCount <= 1) { continue; } StringBuilder msg = new StringBuilder(); int[] indices = mi.GetIndices(); long erg = 1; foreach (int j in indices) { if (msg.Length > 0) { msg.Append(" * "); } msg.Append(pairs[j].B); erg *= pairs[j].B; } if (erg != 1) { if (data.IsIgnored(PrimesBigInteger.ValueOf(erg))) { ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); TextBlock tb = AddTextBlock(counter++, 0); ControlHandler.SetPropertyValue(tb, "Text", Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_testcombi + msg.ToString()); ControlHandler.SetPropertyValue(tb, "Text", string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_testcombiignore, msg, erg)); } else { int sqrt = (int)Math.Sqrt(erg); if (sqrt * sqrt == erg) { ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); TextBlock tb = AddTextBlock(counter++, 0); ControlHandler.SetPropertyValue(tb, "Text", Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_testcombi + msg.ToString()); ControlHandler.SetPropertyValue(tb, "Text", string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_testcombiisquare, msg, erg, erg, sqrt)); foreach (int j in indices) { pairs[j].QuadraticStatus = QuadraticStatus.Part; } return(QSResult.Ok); } else { ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); TextBlock tb = AddTextBlock(counter++, 0); ControlHandler.SetPropertyValue(tb, "Text", Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_testcombi + msg.ToString()); ControlHandler.SetPropertyValue(tb, "Text", string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step3_testcombiisnotsquare, msg, erg)); } } } //Thread.Sleep(m_Delay); } return(QSResult.Failed); // keine Quadrate gefunden }
public void TestGroup() { var mm = new MyInteger(3); var restult = mm.Double().Multiply(3).Add(4).Calc((a, b) => { return 2 + b + a; }, 3).Value; }
//↑と同義 // static void SayHelloFromDeligater() { // Console.WriteLine("hi!"); // } //////////////////// // //////////////////// static void Main() { //変数 string msg = "Hello World"; Console.WriteLine(msg); //定数 const string CONST_MSG = "CONST MESSAGE"; Console.WriteLine(CONST_MSG); //============================== // 型 //============================== // 文字列、文字 // string, char string s = "hello"; char c = 'a'; // 整数値 // byte, short, int, long int i1 = 100; // 浮動小数点数 // float, double double d = 52342.34; float f = 23.3f; // 論理値 // bool -> true, false bool flag1 = true; // 型推論 var m1 = 5; // int var n1 = "world"; // string Console.WriteLine(s); Console.WriteLine(c); Console.WriteLine(i1); Console.WriteLine(d); Console.WriteLine(f); Console.WriteLine(flag1); Console.WriteLine(m1); Console.WriteLine(n1); //============================== // 演算 //============================== // + - * / % var x = 10; // int Console.WriteLine(x / 3); // 3 Console.WriteLine(x % 3); // 1 Console.WriteLine(x / 3.0); // 3.333.... Console.WriteLine(x / (double)3); // 3.333.... // ++ -- var y = 5; y++; Console.WriteLine(y); // 6 y--; Console.WriteLine(y); // 5 var z = 6; // z = z + 10; z += 10; // AND OR NOT // && || ! var flag = true; Console.WriteLine(!flag); //============================== // 文字列 //============================== Console.WriteLine("hello " + "world"); // \n, \t 改行、タブ Console.WriteLine("hell\no wo\trld"); var name1 = "taguchi"; var score1 = 52.3; Console.WriteLine(string.Format("{0} [{1}]", name1, score1)); // taguchi [52.3] Console.WriteLine($"{name1} [{score1}]"); //C# 6以降 Console.WriteLine($"{name1, -10} [{score1, 10}]"); Console.WriteLine($"{name1, -10} [{score1, 10:0.00}]"); Console.WriteLine($"{name1, -10} [{score1 + 25, 10:0.00}]"); //============================== // if //============================== // var score2 = int.Parse(Console.ReadLine()); var score2 = int.Parse("90"); // > >= < <= == != if (score2 > 80) { Console.WriteLine("Great!"); } else if (score2 > 60) { Console.WriteLine("Good!"); } else { Console.WriteLine("so so ...!"); } Console.WriteLine((score2 > 80) ? "Great" : "so so ..."); //============================== // switch //============================== // var signal = Console.ReadLine(); var signal = "red"; switch (signal) { case "red": Console.WriteLine("Stop!"); break; case "blue": case "green": Console.WriteLine("Go!"); break; case "yellow": Console.WriteLine("Caution!"); break; default: Console.WriteLine("wrong signal!"); break; } //============================== // while //============================== // var i2 = 0; var i2 = 100; while (i2 < 10) { Console.WriteLine($"loop:{i2}"); i2++; } do { Console.WriteLine($"loop2:{i2}"); i2++; } while (i2 < 10); //============================== // for //============================== // continue それ以降の処理を中止して次のループへ // break ループ自体を抜ける for (int i = 0; i < 10; i++) { if (i == 3) { continue; } if (i == 5) { break; } Console.WriteLine(i); } //============================== // 配列 //============================== // 配列 int[] scoresA1 = new int[3]; scoresA1[0] = 10; scoresA1[1] = 30; scoresA1[2] = 20; int[] scoresA2 = new int[] { 10, 30, 20 }; int[] scoresA3 = { 10, 30, 20 }; var scoresA4 = new[] { 10, 30, 20 }; scoresA4[1] = 40; Console.WriteLine(scoresA4[1]); Console.WriteLine(scoresA2); Console.WriteLine(scoresA3); //============================== // foreach //============================== var scoresB1 = new[] { 10, 30, 20 }; // for (int i = 0; i < scores.Length; i++) { // Console.WriteLine(scores[i]); // } foreach (int score in scoresB1) { Console.WriteLine(score); } //============================== // メソッド //============================== SayHi1(); Console.WriteLine(SayHi2()); Console.WriteLine(SayHi3()); SayHi4("Tom", 30); // tom 30 SayHi4("Bob"); // bob 23 SayHi4(age: 26, name: "Steve"); // steve 26 //============================== // クラス //============================== User user = new User(); // インスタンス Console.WriteLine(user.name); // me user.SayHi(); // hi! me user.name = "taguchi"; user.SayHi(); // hi! taguchi User tom = new User("Tom"); tom.SayHi(); User user2 = new User(); user2.SayHi(); AdminUser bob = new AdminUser("Bob"); bob.SayHi(); bob.SayHello(); //============================== // プロパティ //============================== Staff staff = new Staff(); Console.WriteLine(staff.Name); staff.Name = "taguchi"; Console.WriteLine(staff.Name); staff.Post = "Chief "; Console.WriteLine(staff.Post); //============================== // インデクサ //============================== Team giants = new Team(); giants[0] = "taguchi"; giants[1] = "fkoji"; giants[2] = "dotinstall"; Console.WriteLine(giants[1]); User.GetCount(); // 0 User userA1 = new User(); User userA2 = new User(); User userA3 = new User(); User.GetCount(); // 3 Console.WriteLine(userA1); Console.WriteLine(userA2); Console.WriteLine(userA3); //============================== // 抽象クラス //============================== Japanese aki = new Japanese(); aki.SayHi(); American mike = new American(); mike.SayHi(); //============================== // インターフェース //============================== Partner partner = new Partner(); partner.Share(); //============================== // ジェネリック //============================== MyData <string> s1 = new MyData <string>(); s1.GetThree("hello"); MyData <double> g1 = new MyData <double>(); g1.GetThree(23.3); MyInteger mi = new MyInteger(); mi.GetThree(55); //============================== // 名前空間 //============================== DotinstallNamespace.Player player1 = new DotinstallNamespace.Player(); Player player2 = new Player(); //using宣言しておけば、namespace省略可。 player1.SayHi(); player2.SayHi(); //============================== // 構造体 //============================== Point p1 = new Point(5, 3); Point p2 = new Point(12, 4); p1.GetInfo(); p2.GetInfo(); //============================== // 列挙型 //============================== Direction dir = Direction.Right; Console.WriteLine((int)Direction.Right); switch (dir) { case Direction.Stay: // そのまま break; case Direction.Right: // 右へ break; case Direction.Left: // 左へ break; } //============================== // 例外 //============================== MyExceptionPractice.Div(10, 0); MyExceptionPractice.Div(10, -3); //============================== // デリゲート //============================== MyDelegate ShowMessage; ShowMessage = SayHiFromDeligater; // デリゲートにメソッドを登録 ShowMessage += SayHelloFromDeligater; //メソッドを追加(マルチキャストデリゲート) ShowMessage -= SayHelloFromDeligater; //登録の解除 ShowMessage(); // 実行 //============================== // 匿名メソッド //============================== MyDelegate ShowMessage2; ShowMessage2 = delegate { Console.WriteLine("hi!(Anonymous methods)"); }; ShowMessage2(); //============================== // ラムダ式 //============================== MyDelegate ShowMessage3; // ラムダ式: 引数 => 処理 ShowMessage3 = () => { Console.WriteLine("hi!(Lambda expression)"); }; ShowMessage3 += () => Console.WriteLine("hello!(Lambda expression)"); ShowMessage3(); //============================== // イベント //============================== MyButton btn = new MyButton(); // メソッドを登録できる(以下ではラムダ式を使用している) btn.MyEvent += () => Console.WriteLine("Button Clicked!"); btn.OnClicked(); //============================== // Collection // - List(データの集合) // - HashSet(順番を持たない、かつ重複を許さないデータの集合。順番を指定してアクセスする事はできない。) // - Dictionary(キーと値でデータを管理していくデータの集合) //※要using System.Collections.Generic; //============================== //------------ // List //------------ List <int> scoresA = new List <int>(); scoresA.Add(30); scoresA.Add(80); scoresA.Add(60); List <int> scoresB = new List <int>() { 30, 80, 60 }; scoresB[1] = 100; Console.WriteLine(scoresB.Count); foreach (var score in scoresB) { Console.WriteLine(score); } //------------ // HashSet //------------ HashSet <int> answers = new HashSet <int>() { 3, 5, 8, 5 }; //重複分は無視される answers.Add(10); // 3, 5, 8, 10 answers.Remove(3); // 5, 8, 10 Console.WriteLine(answers.Contains(3)); // false foreach (var answer in answers) { Console.WriteLine(answer); } //------------ // Dictionary //------------ Dictionary <string, int> registrants = new Dictionary <string, int>() { { "taguchi", 50 }, { "fkoji", 80 }, }; registrants.Add("dotinstall", 40); Console.WriteLine(registrants["fkoji"]); // 80 registrants["taguchi"] = 60; foreach (KeyValuePair <string, int> registrant in registrants) { Console.WriteLine($"{registrant.Key}: {registrant.Value}"); } //============================== // LINQ //============================== //要 using System.Linq; List <double> prices = new List <double>() { 53.2, 48.2, 32.8 }; //------------ // SQL //------------ var resultsA = from price in prices where price * 1.08 > 50.0 select price * 1.08; foreach (var result in resultsA) { Console.WriteLine(result); } //------------ // Method //------------ var results = prices .Select(n => n * 1.08) .Where(n => n > 50.0); foreach (var result in results) { Console.WriteLine(result); } //-----< Sample01 >----- List <Customer> _customers = new List <Customer>(); _customers.Add(new Customer { Name = "Fukuzawa", Age = 35, IsMarried = true, }); _customers.Add(new Customer { Name = "Higuchi", Age = 28, IsMarried = true, }); _customers.Add(new Customer { Name = "Noda", Age = 42, IsMarried = false, }); _customers.Add(new Customer { Name = "Igawa", Age = 21, IsMarried = false, }); _customers.Add(new Customer { Name = "Sawada", Age = 31, IsMarried = true, }); Console.WriteLine("===================="); // All foreach (var customer in _customers) { Console.WriteLine(customer.Name); } Console.WriteLine("===================="); // フィルタリング1 foreach (var customer in _customers.Where(n => n.IsMarried)) { Console.WriteLine(customer.Name); } Console.WriteLine("===================="); // フィルタリング2 foreach (var customer in _customers .Where(n => n.IsMarried) .Where(n => n.Age > 30) ) { Console.WriteLine(customer.Name); } Console.WriteLine("===================="); }