By GokiSoft.com|
19:29 24/06/2020|
C Sharp
[Share Code] Overview kiến thức basic trong lập trình C#
using System;
using System.Collections.Generic;
namespace C1907L
{
class Program
{
static void Main(string[] args)
{
//testBasic();
//testConstruct();
testArray();
}
static void testArray() {
int[] t = new int[10];
int length = t.Length;
//index : 0 -> length - 1 (9)
string[] list = new string[5];
int[] t1 = { 1, 6, 2, 3, 10 };
for (int i = 0; i < t1.Length; i++) {
Console.WriteLine("T[{0}] = {1}", i, t1[i]);
}
int[,] t2 = new int[2, 3];
t2[0, 0] = 19;
List<int> l1 = new List<int>();
l1.Add(12);
l1.Add(22);
Console.WriteLine("index 0 => " + l1[0]);
l1[0] = 2312;
int size = l1.Count;
foreach(int k in l1) {
Console.WriteLine(k);
}
}
static void testConstruct() {
int num = -4;
if(num < 0) {
Console.WriteLine("Num la so am");
}
num = 13;
if(num < 0) {
Console.WriteLine("Num la so a");
} else {
if(num % 2 == 0) {
Console.WriteLine("Num la so chan");
} else {
Console.WriteLine("Num la so le");
}
}
}
static void testBasic() {
Console.WriteLine("Hello World!");
string str1 = "123";
String str2 = "sdfsdfds";
Console.WriteLine("str = " + str1 + ", str2 = " + str2);
Console.WriteLine("str = {0}, str2 = {1} - {0}", str1, str2);
//nhap xuat tu ban phim
string str;
Console.WriteLine("nhap str = ");
str = Console.ReadLine();
Console.WriteLine("Nhap t = ");
int t = int.Parse(Console.ReadLine());
int t1 = 5;
int t2 = ++t1;//t2 = 6 (t1=6)
int t3 = t2++;//t3 = 6 (t2 = 7)
int t4 = t1++ + ++t1 - t2++ - --t3;
//6(t1=7) + 8(t1=8) - 7 (t2=8) - 5 (t3=5)
//t1 = ? 5, 8
//t2 = ? 6, 8
//t3 = ? 5, 6
//t4 = ? 2
Console.WriteLine("T1 = {0}, T2 = {1}, T3 = {2}, T4 = {3}", t1, t2, t3, t4);
int k = 5;
string kk = (k == 5) ? "OK" : "NOT OK";
Console.WriteLine(kk);
}
}
class Abc {
public void ShowOk() {
Console.WriteLine("1231321");
}
}
}
namespace XYZ.OKOK.TTT {
class T {
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)