public void Main(int param1, bool param2, string param3, Method1 param4) { int Salary = 1000; decimal = 20M; Console.WriteLine("Hello World!"); }
static void Main(string[] args) { Method1 createArray = (x) => { int[] a = new int[5]; for (int i = 0; i < a.Length; ++i) { a[i] = x * (i + 1); } return(a); }; Method2 printArray = (x) => { foreach (var el in x) { Console.Write(el + " "); } Console.WriteLine(); }; var array = createArray(5); printArray(array); var array2 = createArray(10); printArray(array2); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.GetEncoding("UTF-8"); /* * Phần 1: Khai báo Anonymous và Anonymous lồng nhau */ var studentUDPM = new { Id = "PH00532", Name = "Dungna29", trangThai = true }; Console.WriteLine("ID = {0} | Name = {1} | TrangThai: {2}", studentUDPM.Id, studentUDPM.Name, studentUDPM.trangThai); var studentUDPM1 = new { Id = "PH00532", Name = "Dungna29", trangThai = true, diaChi = new { soNha = "Nha so 1", quan = "Tây Hồ", thanhPho = "Hà Nội" } }; Console.WriteLine("ID = {0} | Name = {1} | TrangThai: {2} | Địa Chỉ {3}", studentUDPM1.Id, studentUDPM1.Name, studentUDPM1.trangThai, studentUDPM1.diaChi.soNha); /* * Phần 2: Phương thức nặc danh */ Method1 method1 = delegate(int temp) { Console.WriteLine("Đây là phương thức nặc danh. Giá trị {0} ", temp); }; method1(2021);//Gọi đến phương thức nặc danh int temp; Method1 method2 = delegate(int temp) { temp = 2022;//Gọi các biến cục bộ bên ngoài như bình thường Console.WriteLine("Đây là phương thức nặc danh. Giá trị {0} ", temp); }; }
static void Main(string[] args) { Method1 m1 = new Method1(); Console.WriteLine("Enter first number: "); int num1 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter second number: "); int num2 = int.Parse(Console.ReadLine()); bool result = m1.Number(num1 + num2); if (result) { Console.WriteLine("The result is True"); } else { Console.WriteLine("The result is False"); } //Create a function that takes the number of wins, draws and losses, //and calculates the number of points a football team has obtained so far. //Rule - wins get 5 points, draws get 2 point and losses get 0 points. WinLossDraw m2 = new WinLossDraw(); int result1 = m2.Calc(); Console.WriteLine($"The Team got {result1} points"); // A function that takes a two word string separated by space //and returns the concatenated first characters of both the words. //E.g. GetInitials("Bishnu Rawal") => "BR" //GetInitials("Alex Wales") => "AW" GetInitials m3 = new GetInitials(); Console.WriteLine("Enter YourFull Name:"); string name = Console.ReadLine(); string initial = m3.Initials(name); Console.WriteLine($"The Initials are : {initial}"); }
public void Main(int param1, bool param2, string param3, Method1 param4) { int Salary = 1000; decimal = 20M; string name = "John Williams"; try { Console.WriteLine("Hello World!"); } catch (Exception ex) {} try { Console.WriteLine("Hello World!"); } catch (Exception ex) { //empty comment block. } }
static void Main(string[] args) { var methods = new Menu(); methods.FirstMethod = "1"; methods.SecondMethod = "2"; methods.ThirdMethod = "3"; methods.Leave = "Leave"; methods.Choice(); var method1 = new Method1(); method1.One(); var method2 = new Method2(); method2.Two(); var method3 = new Method3(); method3.Three(); var leave = new Leave(); leave.Four(); }
public SecurityController(Method1 _method1, Method2 _method2) { method1 = _method1; method2 = _method2; }
private void btnMethod1_Click(object sender, EventArgs e) { double smallBet, mediumBet, bigBet, minInvest = 0.0, percentTake = 0.0, percentMoneyTake = 0.0; parseBets(out smallBet, out mediumBet, out bigBet); int groups = 0; string topLeaguesValue = "All Leagues"; Invoke(new MethodInvoker(delegate() { int.TryParse(cboxGroup.SelectedItem.ToString(), out groups); topLeaguesValue = cboxTopLeagues.SelectedItem.ToString(); numMinMatches.Minimum = groups; })); string q = @"SELECT sr.Date FROM dbo.Ivnet i, dbo.SportRadar sr WHERE i.Guessed is not null AND i.SportRadarID=sr.ID AND sr.Date>=@FromDate AND sr.Date<=@ToDate GROUP BY sr.Date ORDER BY sr.Date"; // HAVING COUNT(sr.Date)>3 using (SqlConnection connection = new SqlConnection(MainForm.STRCONN)) { connection.Open(); SqlCommand selectCmd = new SqlCommand(q, connection); selectCmd.Parameters.AddWithValue("@FromDate", dtpFrom.Value.ToString("yyyy-MM-dd")); selectCmd.Parameters.AddWithValue("@ToDate", dtpTo.Value.ToString("yyyy-MM-dd")); List <string> dates = new List <string>(); SqlDataReader reader; using (reader = selectCmd.ExecuteReader()) { while (reader.Read()) { dates.Add(reader.GetDateTime(0).ToString("yyyy-MM-dd")); } } Method1 method1 = new Method1(); q = String.Format("SELECT {0} Country,League FROM dbo.Leagues WHERE Season='2011/12' ORDER BY GuessedPercent DESC", topLeaguesValue == "All Leagues" ? "" : topLeaguesValue); method1.topCountries = new List <string>(); method1.topLeagues = new List <string>(); using (reader = new SqlCommand(q, connection).ExecuteReader()) { while (reader.Read()) { method1.topCountries.Add(reader["Country"].ToString()); method1.topLeagues.Add(reader["League"].ToString()); } } method1.Connection = connection; method1.groups = groups; method1.minMatches = (int)numMinMatches.Value; method1.smallBet = smallBet; method1.mediumBet = mediumBet; method1.bigBet = bigBet; method1.isTip1 = cbTip1.Checked; method1.isTipX = cbTipX.Checked; method1.isTip2 = cbTip2.Checked; method1.isScore1 = cbScore1.Checked; method1.isScoreX = cbScoreX.Checked; method1.isScore2 = cbScore2.Checked; method1.isSmallBet = cbSmallBet.Checked; method1.isMediumBet = cbMediumBet.Checked; method1.isBigBet = cbBigBet.Checked; method1.isGroupAll = cbGroupAll.Checked; method1.isIncremental = cbIncrement.Checked; if (method1.isIncremental) { double.TryParse(tbMinInvest.Text, out minInvest); double.TryParse(tbPercentTake.Text, out percentTake); double.TryParse(tbMaxInvest.Text, out method1.maxInvest); double.TryParse(tbMaxGroupInvest.Text, out method1.maxGroupInvest); method1.minInvest = minInvest; } foreach (string date in dates) { method1.propInvest = 1.0; method1.processRound(date, false); if (method1.isIncremental) { method1.propInvest = method1.minInvest / method1.investedMoney; } //Console.WriteLine(", maxInvest: {0}, investedMoney: {1}", method1.maxInvest, method1.investedMoney); //Console.WriteLine("minInvest: {0}, percentMoneyTake: {1}", method1.profit, percentMoneyTake); method1.processRound(date); if (method1.isIncremental) { if (cbPercentTake.Checked && method1.profit > 0) { percentMoneyTake = method1.profit * percentTake / 100; method1.allProfit += percentMoneyTake; method1.profit -= percentMoneyTake; } method1.minInvest = method1.minInvest + method1.profit; if (method1.minInvest < minInvest) { method1.minInvest = minInvest; } if (cbMaxInvest.Checked && method1.minInvest > method1.maxInvest) { method1.minInvest = method1.maxInvest; } } } string summary = @"<div style='border-top:3px solid black;'><table> <thead> <tr cellspan='2'><th>Summary:</th></tr> </thead> <tbody> <tr><td>All Investment:</td><td><b>{0:0.00}</b></td> <td> </td><td>Won Rounds</td><td><b>{3}</b></td></tr> <tr><td>All Profit:</td><td><b>{1:0.00}</b></td> <td> </td><td>Lost Rounds</td><td><b>{4}</b></td></tr> <tr><td>Percent:</td><td><b>{2:0}%</b></td> <td> </td><td></td><td><b></b></td></tr> </tbody> </table></div>"; summary = String.Format(summary, method1.allInvestment, method1.allProfit, method1.allProfit / method1.allInvestment * 100, method1.wonRounds, method1.lostRounds); browser.DocumentText = "<html><head></head><body style='font-family:Verdana;font-size:12px;'>" + method1.html + summary + "</body></html>"; } }