By GokiSoft.com|
10:47 07/10/2021|
C Sharp
[Video] Tìm hiểu biến, toán tử, mệnh đề điều kiện, lặp (for, white, do .. while), switch - mảng trong C# - Khoá học lập trình C# - C2009G
Tóm Tắt Nội Dung Học
Nội dung kiến thức môn học C#:
- Kiến thức căn bản:
- Khai báo biến + toán tử
- Mệnh đề điều kiện (if, else, switch)
- Vòng lặp (for, while, do .. while)
- Mảng index (int[] t = new int[5])
- OOP:
- Tính chất đóng gói
- access propeties (public, protected, private, default (internal - friendly))
- Tính chất kế thừa
- override
- overloading
- Tính chất đa hình
- Tính chất trừu tượng
- Interface
- Event + Delegate + Collection (List, Hashtable, ...)
Kiến khác:
- Tìm hiều FILE (text, object)
- JSON (convert object|list -> json, json -> object|list)
- Kết nối CSDL + C# Console
======================================================================================
Nội dung buổi học hôm này:
- So sanh ngôn ngữ lập trình C/C++ & Java & C#
- Cài đặt môi trường
- Kiến thức căn bản:
- Khai báo biến + toán tử
- Mệnh đề điều kiện (if, else, switch)
- Vòng lặp (for, while, do .. while)
- Mảng index (int[] t = new int[5])
START***
C/C++ -> DevC (IDE) -> Viết code -> Compile -> exe (binary) (Gửi cho KH sử dụng) -> PC (Running)
Java -> Netbean (IDE) -> Viết code -> Compile -> jar (byte code) (Gửi cho KH sử dung) -> JVM (JDK) -> binary -> PC (running)
C# -> Visual Studio (IDE) -> Viết code -> Compile -> CIL (exe) (Gửi cho KH sử dụng) -> .NET -> binary -> PC (running)
Cài đặt môi trường:
- .NET >> https://dotnet.microsoft.com/download/dotnet-framework
.NET Framwwork -> License -> Microsoft -> WINDOW
.NET Core -> Open Souce -> Microsoft -> Cross platform -> WINDOW/LINUX/UBUNTU...
- IDE >> https://visualstudio.microsoft.com/
>> https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=16
Tạo dự án đầu tiên:
Souce Code Tham Khảo
/***
* Nhap mon C# -> Cac ban doc theo tung buoc B1 -> B2 -> B3 -> .v.v
*/
//B5. using -> Dc su dung de them thu vien vao trong du an.
using System;
//B4. Namespace <-> Package (Java)
//B4. Namespace -> Nhom class object -> Co nhieu class object
namespace Lesson01
{
//B3. Ten Class Object ko nhat thiet trung Ten File
class Program01
{
//B2. Tao ra rat nhieu class object -> Nhung chi co duy nhat 1 method (static voi Main)
//B2. Noi bat dau cho chuong trinh chay.
static void Main(string[] args)
{
//B1.Hien thi ra man hinh -> Hello World
Console.WriteLine("Hello World!");
//B8. Khai bao bien + toan tu
//Test01();
//B9. Tim hieu toan tu
//Test02();
//B10. Menh de dieu kien + Loop
//Test03();
//B11. Khai bao mang
Test04();
}
static void Test04()
{
//Khai bao mang so nguyen 3 phan tu
int[] t = new int[3];
//Length: 3, Index: 0 -> Length - 1: 0 -> 2
//Gan du lieu
t[0] = 2;
t[1] = 10;
t[2] = 1;
Console.WriteLine("Nhap t[1] = ");
t[1] = int.Parse(Console.ReadLine());
Console.WriteLine("t[0] = " + t[0]);
Console.WriteLine("t[{0}] = {1}", 1, t[1]);
for(int i=0;i<t.Length;i++)
{
Console.WriteLine("t[{0}] = {1}", i, t[i]);
}
foreach(int v in t)
{
Console.WriteLine("v = " + v);
}
//Khai bao mang chua cac phan tu ban dau
int[] k = { 1, 6, 2 };
foreach (int v in k)
{
Console.WriteLine("v = " + v);
}
//Tuong tu -> khai mang float, double, char, string, ...
//Thay int -> float, int -> double, int -> char, int -> string
string[] list = new string[5];
char[] cList = new char[3];
}
static void Test03()
{
int value = 2;
switch(value)
{
case 1:
Console.WriteLine("Hello A");
break;
case 2:
case 3:
Console.WriteLine("Hello BC");
break;
default:
Console.WriteLine("Hello D");
break;
}
int i = 0, j;
while(i<5)
{
j = 0;
while(j<=i)
{
Console.Write("*");
j++;
}
Console.WriteLine();
i++;
}
}
static void Test02()
{
int x = 5;
int y = x++;//x = 6, y = 5
Console.WriteLine("x = {0}, y = {1}", x, y);
int t = ++x;//x = 7, t = 7
Console.WriteLine("x = {0}, y = {1}, t = {2}", x, y, t);
//x = 7, y = 5, t = 7
int z = x++ + ++x - --y - --t + y--;
//z = 7(x=8) + 9(x=9) - 4(y=4) - 6(t=6) + 4(y=3)
//x = 9, y = 3, t = 6, z = 10
Console.WriteLine("x = {0}, y = {1}, t = {2}, z = {3}", x, y, t, z);
string s = (z == 10) ? "OK" : "Goodbye";
Console.WriteLine("s = " + s);
}
static void Test01()
{
int x, y = 10;
x = 5;
int z = x + y;
Console.WriteLine("x = " + x + ", y = " + y + ", z = " + z);
Console.WriteLine("x = {0}, y = {1} -> {0}, z = {2} -> {0}", x, y, z);
double d1;
float f1;
char c = 'A';
//Khai bao chuoi
string s1 = "SINH VIEN";//Su dung cach nay de khai bao chuoi
Console.WriteLine("s1 -> " + s1);
String s2 = "Aptech";
Console.WriteLine("s2 -> " + s2);
//Nhap du lieu tu keyboard
Console.WriteLine("Nhap s1 = ");
s1 = Console.ReadLine();
Console.WriteLine("s1 = " + s1);
Console.WriteLine("Nhap x = ");
x = int.Parse(Console.ReadLine());
//x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("x = " + x);
//float.Parse(Console.Readline())
int @k, @int;
@k = 6;
@int = 100;
Console.WriteLine("k = {0}, int = {1}", k, @int);
}
}
//B6: Duplicate nhieu class object
class Program02
{
static void Test(string[] args)
{
Console.WriteLine("Hello World!");
}
}
class Program03
{
static void Test(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
//B7. Duplicate nhieu namespace trong file
namespace Lesson02
{
class Program01
{
static void ShowMsg(string[] args)
{
Console.WriteLine("Hello World!");
}
}
class Program03
{
static void Test(string[] args)
{
Console.WriteLine("Hello World!");
}
}
class Program04
{
static void Test(string[] args)
{
Console.WriteLine("Hello World!");
}
}
class Program05
{
static void Test(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)