Учим C# зная basic Цель данной темы: разместить в интернет программы по каким возможно быстро выучить C# зная basic Программы созданы мной на основе моей главной программы где запрограммирован мой алгоритм в нескольких вариантах и теперь программирую на C# сразу без перевода из basic ? Почему C# & basic ? Потому что компилируемые и есть онлайн компиляторы и компилятор C# включен в Windows 7 Framework Программы проверены: работают и каждый может проверить и лично я компилирую и стартую через простейший bat Квадратное уравнение qb64 ' quadratic equation QB64 DAV INPUT "INPUT A"; A INPUT "INPUT B"; B INPUT "INPUT C"; C D = B ^ 2 - 4 * A * C IF D < 0 THEN PRINT "D<0 ": END PRINT "OTBET: " PRINT "D ="; D X1 = (-B + SQR(D)) / (2 * A) X2 = (-B - SQR(D)) / (2 * A) PRINT "X1 ="; X1 PRINT "X2 ="; X2 END Квадратное уравнение C#// quadratic equation C# DAV using System; using System.Text; using System.IO; namespace DAV { class Program { static void Main(string[] args) { Console.Write("INPUT A: "); long a = Convert.ToInt32(Console.ReadLine()); Console.Write("INPUT B: "); long b = Convert.ToInt32(Console.ReadLine()); Console.Write("INPUT C: "); long c = Convert.ToInt32(Console.ReadLine()); long d = (b * b - 4 * a * c); Console.WriteLine("OTBET: "); Console.Write("D = "); Console.WriteLine(d); var x1 = (-b + Math.Sqrt(d)) / (2 * a); var x2 = (-b - Math.Sqrt(d)) / (2 * a); Console.Write("X1 = "); Console.WriteLine(x1); Console.Write("X2 = "); Console.WriteLine(x2); Console.ReadKey(); } } } 'Угадай число RANDOMIZE TIMER s = INT(RND * 100) t = 0 10 PRINT: t = t + 1: INPUT "your variant"; a IF a < s THEN PRINT "need MORE": GOTO 10 IF a > s THEN PRINT "need less": GOTO 10 PRINT "win by"; t; "steps" END //Угадай число using System; using System.Text; namespace DAV { class Program { static void Main(string[] args) { Random rand = new Random(); int s = rand.Next(100); int t = 0; dav: Console.WriteLine(); t++; Console.Write("your variant "); string d = Console.ReadLine(); int a = Convert.ToInt32(d); if(a > s) { Console.WriteLine("need less"); goto dav; } else if(a < s) { Console.WriteLine("need MORE"); goto dav; } Console.Write("win by "); Console.Write(t); Console.Write(" steps"); Console.ReadKey(); } } } 'Угадывает 1 из 1000000 RANDOMIZE TIMER t=0:h1=0:h2=10^6 c=INT(RND*h2) 'comp h=INT(RND*h2) 'human 10 t=t+1: PRINT t; c; h; IF h<c THEN PRINT "MORE": a=h: h=INT((h+h2)/2): h1=a: GOTO 10 IF h>c THEN PRINT "less": a=h: h=INT((h1+h)/2): h2=a: GOTO 10 PRINT "win by "; t; " steps" END //Угадывает 1 из 1000000000 за =log(10^9;2) за 30 ходов using System; using System.Text; namespace DAV { class Program { static void Main(string[] args) { int h2 = 1000000000;//or 500 int h1 = 0; Random rand = new Random(); int c = rand.Next(h2); //computer int h = rand.Next(h2); //human or h2/2; int t = 0; dav: t++; Console.WriteLine(); Console.Write(t); Console.Write(" "); Console.Write(c); Console.Write(" "); Console.Write(h); Console.Write(" "); if(h < c) { Console.Write("MORE"); int a = h; h = (h + h2) / 2; h1 = a; goto dav; } else if(h > c) { Console.Write("less"); int a = h; h = (h1 + h) / 2; h2 = a; goto dav; } Console.Write("win by "); Console.Write(t); Console.Write(" steps"); Console.ReadKey(); } } }' псевдо 3д рельеф под 45' с разными высотами и массив SCREEN 12 RANDOMIZE TIMER DIM a(12, 12) FOR t = 1 TO 12 FOR x = 1 TO 12 FOR y = 1 TO 12 a(x, y) = INT(RND * 20) NEXT: NEXT CLS FOR y = 1 TO 12 FOR x = 1 TO 11 LINE (50 + 20 * x + 20 * y, 400 - 20 * y - a(x, y))-(50 + 20 * (x + 1) + 20 * y, 400 - 20 * y - a(x + 1, y)), y FOR z = 1 TO 2 * 10 ^ 5: NEXT ' SLEEP 1 NEXT: NEXT FOR x = 1 TO 12 FOR y = 1 TO 11 LINE (50 + 20 * x + 20 * y, 400 - 20 * y - a(x, y))-(50 + 20 * (x + 1) + 20 * y, 400 - 20 * (y + 1) - a(x, y + 1)), x FOR z = 1 TO 2 * 10 ^ 5: NEXT ' SLEEP 1 NEXT: NEXT SLEEP 1 NEXT END //daRELIEF.cs using System; using System.Drawing; using System.Windows.Forms; class daRELIEF: Form { public static void Main() { Application.Run(new daRELIEF()); } public daRELIEF() { Text = "daRELIEF"; BackColor = System.Drawing.Color.Blue; ForeColor = System.Drawing.Color.Red; ResizeRedraw = true; Width = 600; Height = 360; } protected override void OnPaint(PaintEventArgs dan) { int[,] a = new int[22, 22]; Random rand = new Random(); Graphics da = dan.Graphics; SolidBrush BlueBrush = new SolidBrush(Color.Blue); for (int k = 1; k < 22; k++) //da: { // массив высот for (int x = 1; x <=12; x++) for (int y = 1; y <=12; y++) a[x,y]=rand.Next(20); da.FillRectangle(BlueBrush, 20, 20, 550, 300); // паралл Х красный for (int y = 1; y <=12; y++) for (int x = 1; x <=11; x++) da.DrawLine(new Pen(Color.Red, x/2), new Point(50+20*x+20*y, 300-20*y-a[x,y]), new Point(50+20*(x+1)+20*y, 300-20*y-a[x+1,y])); // паралл У красный for (int x = 1; x <=12; x++) for (int y = 1; y <=11; y++) da.DrawLine(new Pen(Color.Red, y/2), new Point(50+20*x+20*y, 300-20*y-a[x, y]), new Point(50+20*(x+1)+20*y, 300-20*(y+1)-a[x, y+1])); System.Threading.Thread.Sleep(1000); Array.Clear(a, 0, 22); }//k goto da; } } соединяет все 8 точек между собой классическая школьная задача и для вычисления суммы всех длин используется корень из 1-й программы про квадратное уравнение //DAV.cs using System; using System.Drawing; using System.Windows.Forms; class DAV: Form { public static void Main() { Application.Run(new DAV()); } public DAV() { Text = "DAV"; BackColor = SystemColors.WindowText; ForeColor = SystemColors.Window; ResizeRedraw = true; Width = 600; Height = 360; } protected override void OnPaint(PaintEventArgs dan) { int[] x = new int[10]; int[] y = new int[10]; Random rand = new Random(); for (int i = 1; i <=8; i++) { x[i]=50+rand.Next(400); y[i]=50+rand.Next(200); } Graphics da = dan.Graphics; Pen pen = new Pen(ForeColor); for (int i = 1; i <=8; i++) da.DrawEllipse(new Pen(Color.Magenta, i), x[i]-10, y[i]-5, 20, 10); for (int i = 1; i <= 7; i++) { for (int j = i+1; j <= 8; j++) { Graphics dav = dan.Graphics; dav.DrawLine(new Pen(Color.Red, i), new Point(x[i], y[i]), new Point(x[j], y[j])); System.Threading.Thread.Sleep(200); } // j }//i System.Threading.Thread.Sleep(5000); Array.Clear(x, 0, 10); Array.Clear(y, 0, 10); } } параметрическая анимация кот перемещается и кивает головой и дышит //cat.cs using System; using System.Drawing; using System.Windows.Forms; class cat: Form { public static void Main() { Application.Run(new cat()); } public cat() { Text = "cat"; BackColor = System.Drawing.Color.Blue; ForeColor = System.Drawing.Color.Red; ResizeRedraw = true; Width = 600; Height = 360; } protected override void OnPaint(PaintEventArgs dan) { Pen pen = new Pen(ForeColor); SolidBrush BlueBrush = new SolidBrush(Color.Blue); Graphics dav = dan.Graphics; for (int k = 1; k <=5; k++) for (int x = -50; x <=50; x++) { int y=0; if (x< 50) y=-x/5; if (x< 25) y= x/5; if (x<-25) y=-x/5; if (x<-50) y= x/5; dav.FillRectangle(BlueBrush, 0, 120, 600, 200); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+195, 225, 10, -80); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+200, 200, 100, 50); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+280, y+170, 50, 50); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+290, y+190, 10, 10);//x/5, x/5 dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+294, y+194, 2, 2); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+310, y+190, 10, 10);//x/5, x/5 dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+314, y+194, 2, 2); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+280, y+205, 25, 10); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+310, y+205, 25, 10); dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+280, y+190), new Point(x*k+280, y+160)); dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+290, y+175), new Point(x*k+280, y+160)); dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+330, y+190), new Point(x*k+330, y+160)); dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+320, y+175), new Point(x*k+330, y+160)); dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+210, 240), new Point(x*k+210, 280)); dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+220, 230), new Point(x*k+220, 290)); dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+280, 230), new Point(x*k+280, 290)); dav.DrawLine(new Pen(Color.Magenta, 3), new Point(x*k+290, 240), new Point(x*k+290, 280)); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+205, 275, 10, 10); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+215, 285, 10, 10); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+275, 285, 10, 10); dav.DrawEllipse(new Pen(Color.Magenta, 3), x*k+285, 275, 10, 10); System.Threading.Thread.Sleep(10); } } } типовое оформление для онлайн компилятораи для форумов: структура сдвинута влево и есть заголовок для сохранения и для поиска // name.cs // for copypaste filename cs bat exe // https://rextester.com/BXWC6536 // adress online using System; using System.Text; namespace name { class name { static void Main(string[] args) { int[,] a = new int[22,22]; Random rand = new Random(); for (int x = 1; x <=12; x++) for (int y = 12; y >=1; y--) a[x,y]=rand.Next(10); for (int x = 1; x <=12; x++) { for (int y = 12; y >=1; y--) { Console.Write(a[x,y]); Console.Write(" "); } Console.WriteLine(); } Console.ReadKey(); } } } со временем понял про оформление циклов короче однако предыдущие программы не переписываю а также есть наработки про текстовые строки и про запись/считывание и есть главная программа далее исследую Windows окна и формы