By GokiSoft.com|
15:14 14/05/2021|
C Sharp
[Share Core] Tìm hiểu kiến thức căn bản C# - Phần 1 - Lập trình C#
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
Console.WriteLine("Hello World");
int x1 = 5, x2 = 6;
int x3 = ++x1 + ++x2;
Console.WriteLine("x3 = {0}", x3);
int x4 = x1++ + ++x1 - --x3 + x2++ + 1;
//5 + 6 - 13 + 6 + 1 = 5 -> DUC 01 -> 03
//5 + 6 - 12 + 6 + 1 = 6 -> DUC 02 -> 04
//6 + 8 - 12 + 7 + 1 = 10 -> DAT -> 05
Console.WriteLine("x4 = {0}", x4);
int day = 5;
switch(day) {
case 1:
Console.WriteLine("S 1");
break;
case 2:
Console.WriteLine("M 2");
break;
case 3:
Console.WriteLine("T 3");
break;
case 4:
Console.WriteLine("W 4");
break;
case 5:
Console.WriteLine("T 5");
break;
case 6:
Console.WriteLine("F 6");
break;
case 7:
Console.WriteLine("S 7");
break;
default:
Console.WriteLine("Default");
break;
}
int rows = 2;
int columns = 2;
Console.WriteLine("Ma Tran Vuong - START");
for(int i=0;i<rows;i++) {
for(int j=0;j<columns;j++) {
Console.Write("{0} ", i*j);
}
Console.WriteLine("");
}
Console.WriteLine("Ma Tran Vuong - END");
int x = 5123456;
float y = 10324.34343434F;
string str = "Tran Van\" A";
String s2 = "Tran Van B";
Console.WriteLine("x = " + x + ", y = " + y + ", str = " + str);
//C# hay hon so vs C/C++/Java
Console.WriteLine("x = ${0:#,###}, y = ${1:#,###.##}, str = {2} - {0} - {3}", x, y, str, s2);
//Nhap du lieu trong C#
Console.WriteLine("Nhap s3 = ");
string s3 = Console.ReadLine();
Console.WriteLine("Ket qua: {0}", s3);
Console.WriteLine("Nhap x = ");
x = Int32.Parse(Console.ReadLine());
Console.WriteLine("Ket qua: {0}", x);
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)