Mô tả bài toán
Tạo ứng dụng Console, khai báo các biến tương ứng với các kiểu dữ liệu có thể lưu trữ được thông tin cho:- Mẫu Lý lịch Công chức A2
- Mẫu Hóa đơn Bán hàng
Cách giải quyết
Xem source code Tham khảo để biết cách khai báo một số kiểu dữ liệu trong C#. Ví dụ:csharp
1string hoTen = "Dương Nguyễn Phú Cường";2int gioiTinh = 0; //0: Nam; 1: Nữ; 2: Không công bố3string[] diaChi = new string[5]; // Mỗi người có 5 địa chỉ4diaChi[0] = "130 Xô Viết Nghệ Tỉnh, Quận Ninh Kiều, TP Cần Thơ";5diaChi[1] = "01 Lý Tự Trọng, Quận Ninh Kiều, TP Cần Thơ";6diaChi[2] = "";7diaChi[3] = "";8diaChi[4] = "";9DateTime ngaySinh = new DateTime(1989, 11, 06, 04, 00, 00);Source code
csharp
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5 6namespace DataTypeInCSharp7{8 class Program9 {10 static void Main(string[] args)11 {12 // https://learnxinyminutes.com/docs/csharp/13 ///////////////////////////////////////////////////14 // Types & Variables15 //16 // Declare a variable using <type> <name>17 ///////////////////////////////////////////////////18 19 // Sbyte - Signed 8-bit integer20 // (-128 <= sbyte <= 127)21 sbyte fooSbyte = 100;22 23 // Byte - Unsigned 8-bit integer24 // (0 <= byte <= 255)25 byte fooByte = 100;26 27 // Short - 16-bit integer28 // Signed - (-32,768 <= short <= 32,767)29 // Unsigned - (0 <= ushort <= 65,535)30 short fooShort = 10000;31 ushort fooUshort = 10000;32 33 // Integer - 32-bit integer34 int fooInt = 1; // (-2,147,483,648 <= int <= 2,147,483,647)35 uint fooUint = 1; // (0 <= uint <= 4,294,967,295)36 37 // Long - 64-bit integer38 long fooLong = 100000L; // (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807)39 ulong fooUlong = 100000L; // (0 <= ulong <= 18,446,744,073,709,551,615)40 // Numbers default to being int or uint depending on size.41 // L is used to denote that this variable value is of type long or ulong42 43 // Double - Double-precision 64-bit IEEE 754 Floating Point44 double fooDouble = 123.4; // Precision: 15-16 digits45 46 // Float - Single-precision 32-bit IEEE 754 Floating Point47 float fooFloat = 234.5f; // Precision: 7 digits48 // f is used to denote that this variable value is of type float49 50 // Decimal - a 128-bits data type, with more precision than other floating-point types,51 // suited for financial and monetary calculations52 decimal fooDecimal = 150.3m;53 54 // Boolean - true & false55 bool fooBoolean = true; // or false56 57 // Char - A single 16-bit Unicode character58 char fooChar = 'A';59 60 // Strings -- unlike the previous base types which are all value types,61 // a string is a reference type. That is, you can set it to null62 string fooString = "\"escape\" quotes and add \n (new lines) and \t (tabs)";63 Console.WriteLine(fooString);64 65 // You can access each character of the string with an indexer:66 char charFromString = fooString[1]; // => 'e'67 // Strings are immutable: you can't do fooString[1] = 'X';68 69 // Compare strings with current culture, ignoring case70 string.Compare(fooString, "x", StringComparison.CurrentCultureIgnoreCase);71 72 // Formatting, based on sprintf73 string fooFs = string.Format("Check Check, {0} {1}, {0} {1:0.0}", 1, 2);74 75 // Dates & Formatting76 DateTime fooDate = DateTime.Now;77 Console.WriteLine(fooDate.ToString("hh:mm, dd MMM yyyy"));78 79 // Verbatim String80 // You can use the @ symbol before a string literal to escape all characters in the string81 string path = "C:\\Users\\User\\Desktop";82 string verbatimPath = @"C:\Users\User\Desktop";83 Console.WriteLine(path == verbatimPath); // => true84 85 // You can split a string over two lines with the @ symbol. To escape " use ""86 string bazString = @"Here's some stuff on a new line! ""Wow!"", the masses cried";87 88 // Use const or read-only to make a variable immutable89 // const values are calculated at compile time90 const int HoursWorkPerWeek = 9001;91 92 ///////////////////////////////////////////////////93 // Data Structures94 ///////////////////////////////////////////////////95 96 // Arrays - zero indexed97 // The array size must be decided upon declaration98 // The format for declaring an array is follows:99 // <datatype>[] <var name> = new <datatype>[<array size>];100 int[] intArray = new int[10];101 102 // Another way to declare & initialize an array103 int[] y = { 9000, 1000, 1337 };104 105 // Indexing an array - Accessing an element106 Console.WriteLine("intArray @ 0: " + intArray[0]);107 // Arrays are mutable.108 intArray[1] = 1;109 110 // Lists111 // Lists are used more frequently than arrays as they are more flexible112 // The format for declaring a list is follows:113 // List<datatype> <var name> = new List<datatype>();114 List<int> intList = new List<int>();115 List<string> stringList = new List<string>();116 List<int> z = new List<int> { 9000, 1000, 1337 }; // initialize117 // The <> are for generics - Check out the cool stuff section118 119 // Lists don't default to a value;120 // A value must be added before accessing the index121 intList.Add(1);122 Console.WriteLine("intList @ 0: " + intList[0]);123 124 // Others data structures to check out:125 // Stack/Queue126 // Dictionary (an implementation of a hash map)127 // HashSet128 // Read-only Collections129 // Tuple (.Net 4+)130 131 //132 // TODO: Khai báo các Biến dữ liệu cần thiết để có thể lưu trữ được Mẫu thông tin Lý lịch A2133 // https://nentang.vn/khoa-hoc/dot-net/lap-trinh-can-ban-c-sharp/bai-hoc/khai-bao-cac-kieu-du-lieu-cho-mau-ly-lich-a2-va-mau-hoa-don-ban-hang/134 135 //136 // TODO: Khai báo các Biến dữ liệu cần thiết để có thể lưu trữ được Mẫu hóa đơn bán hàng137 // https://nentang.vn/khoa-hoc/dot-net/lap-trinh-can-ban-c-sharp/bai-hoc/khai-bao-cac-kieu-du-lieu-cho-mau-ly-lich-a2-va-mau-hoa-don-ban-hang/138 139 }140 }141}
