Trang chủ
Bài viết mới
Diễn đàn
Bài mới trên hồ sơ
Hoạt động mới nhất
VIDEO
Mùa Tết
Văn Học Trẻ
Văn Học News
Media
New media
New comments
Search media
Đại Học
Đại cương
Chuyên ngành
Triết học
Kinh tế
KHXH & NV
Công nghệ thông tin
Khoa học kĩ thuật
Luận văn, tiểu luận
Phổ Thông
Lớp 12
Ngữ văn 12
Lớp 11
Ngữ văn 11
Lớp 10
Ngữ văn 10
LỚP 9
Ngữ văn 9
Lớp 8
Ngữ văn 8
Lớp 7
Ngữ văn 7
Lớp 6
Ngữ văn 6
Tiểu học
Thành viên
Thành viên trực tuyến
Bài mới trên hồ sơ
Tìm trong hồ sơ cá nhân
Credits
Transactions
Xu: 0
Đăng nhập
Đăng ký
Có gì mới?
Tìm kiếm
Tìm kiếm
Chỉ tìm trong tiêu đề
Bởi:
Hoạt động mới nhất
Đăng ký
Menu
Đăng nhập
Đăng ký
Install the app
Cài đặt
Chào mừng Bạn tham gia Diễn Đàn VNKienThuc.com -
Định hướng Forum
Kiến Thức
- HÃY TẠO CHỦ ĐỀ KIẾN THỨC HỮU ÍCH VÀ CÙNG NHAU THẢO LUẬN Kết nối:
VNK X
-
VNK groups
| Nhà Tài Trợ:
BhnongFood X
-
Bhnong groups
-
Đặt mua Bánh Bhnong
CÔNG NGHỆ
Công Nghệ Thông Tin
Code
Tìm hiểu về Generic trong C#
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Trả lời chủ đề
Nội dung
<blockquote data-quote="uocmo_kchodoi" data-source="post: 177639" data-attributes="member: 165510"><p><a href="https://vnkienthuc.com/forums/code.377/" target="_blank"><span style="font-size: 18px">Generic </span></a><span style="font-size: 18px">là 1 tính năng mới trong .NET Framework 2.0 và và được tích hợp sâu trong Common Language Runtime (CLR). Trong .NET Framework, Generic được giới thiệu là khái niệm về các kiểu tham số và được dùng để thiết kế class và phương thức nhằm để trì hoãn chỉ ra kiểu dữ liệu cho đến khi lớp hoặc phương thức được khai báo hoặc khởi tạo.</span></p><p><span style="font-size: 18px"></span></p><p style="text-align: center"><span style="font-size: 18px">[ATTACH=full]3132[/ATTACH]</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Ví dụ, bằng cách sử dụng tham số T là tham số chung, bạn có thể tạo 1 class duy nhất mà khi tham chiếu tới, bạn sẽ không gặp bất kỳ lỗi nào xảy ra trong lúc runtime khi ép kiểu hoặc boxing (chuyển giá trị từ value type sang reference type)</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><strong>Sự ra đời của Generic</strong></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Rất nhiều người trong chúng ta </span><a href="https://vnkienthuc.com/threads/tim-hieu-ve-lop-bitarray-trong-c.77384/" target="_blank"><span style="font-size: 18px">sử dụng generic </span></a><span style="font-size: 18px">mà không biết rằng nó là generic. Ví dụ, khi muốn tạo 1 danh sách các học sinh, ta thường viết:</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">//Một list chứa các object là Student</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">List<Student> students = new List<Student>();</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">students.Add(new Student()); //Code đúng</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">students.Add(new Car()); //Compile lỗi</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">//Lấy học sinh đầu tiên.</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">//Compiler tự hiểu kết quả là Student</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">Student first = students.First();</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Generics ở trong 2 dấu ngoặc nhọn đấy bạn <>.</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Để dễ hiểu, ta hãy quay lại thời .NET 1.0, khi generic chưa xuất hiện:</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">//Không có generic</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">//Một list chứa các object</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">List students = new List();</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">students.Add(new Student()); //Compile bình thường</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">students.Add(new Car()); //Compile bình thường</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">//Lấy object đầu tiên, phải ép kiểu sang Student</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">Student first = (Student)students.First();</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Không có generic, compiler không thể check lỗi lúc compiler. Do đó, ở dòng 2, ta có thể thêm 1 object Car và list gồm các object Student. Khi lấy 1 phần tử ra, ta cũng phải ép kiểu, vì compiler chỉ hiểu nó là 1 object. Vì những lý do đó, generic đã được thêm vào ở .NET 2.0.</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><strong>Tác dụng của generic:</strong></span></p><ul> <li data-xf-list-type="ul"><span style="font-size: 18px">Giúp tái sử dụng code. Ví dụ: Ta chỉ cần viết class List<T>, T ở đây có thể là bất kì class gì.</span></li> <li data-xf-list-type="ul"><span style="font-size: 18px">Hỗ trợ compiler bắt lỗi trong quá trình compiler (Hạn chế được tình trạng như dòng 2).</span></li> <li data-xf-list-type="ul"><span style="font-size: 18px">Không còn phải ép kiểu từ object.</span></li> </ul><p><span style="font-size: 18px"><strong>Ví dụ:</strong></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Bạn tạo hai lớp có tên lần lượt là TestGeneric, TestCsharp như sau:</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Lớp TestGeneric:</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">using System;</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">using System.Collections.Generic;</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">namespace VietJackCsharp</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">{</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> class TestGeneric <T></span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> private T[] array;</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> public TestGeneric(int size)</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> array = new T[size + 1];</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> public T getItem(int index)</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> return array[index];</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> public void setItem(int index, T value)</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> array[index] = value;</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">}</span></em></span></p><p><span style="font-size: 18px">Lớp TestCsharp:</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">using System;</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">using System.Collections;</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">namespace VietJackCsharp</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">{</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> class TestCsharp</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> static void Main(string[] args)</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> Console.WriteLine("Vi du minh hoa Generic trong C#");</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> Console.WriteLine("-------------------------------------");</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> </span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> //khai bao mot mang cac so nguyen</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> TestGeneric<int> intArray = new TestGeneric<int>(5);</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> //thiet lap cac gia tri</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> for (int c = 0; c < 5; c++)</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> intArray.setItem(c, c * 5);</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> //lay va hien thi cac gia tri</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> for (int c = 0; c < 5; c++)</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> Console.Write(intArray.getItem(c) + " ");</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> Console.WriteLine();</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> //khai bao mot mang ky tu</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> TestGeneric<char> charArray = new TestGeneric<char>(5);</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> //thiet lap gia tri</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> for (int c = 0; c < 5; c++)</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> charArray.setItem(c, (char)(c + 97));</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> //lay va hien thi cac gia tri</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> for (int c = 0; c < 5; c++)</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> {</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> Console.Write(charArray.getItem(c) + " ");</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> Console.WriteLine();</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> </span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> Console.ReadKey();</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3"> }</span></em></span></p><p><span style="font-size: 18px"><em><span style="color: #5900b3">}</span></em></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Nếu bạn không</span><a href="https://vnkienthuc.com/threads/tim-hieu-ve-lop-hashtable-trong-c.77360/" target="_blank"><span style="font-size: 18px"> sử dụng lệnh Console</span></a><span style="font-size: 18px">.ReadKey(); thì chương trình sẽ chạy và kết thúc luôn (nhanh quá đến nỗi bạn không kịp nhìn kết quả). Lệnh này cho phép chúng ta nhìn kết quả một cách rõ ràng hơn.</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Biên dịch và chạy chương trình C# trên sẽ cho kết quả sau:</span></p><p><span style="font-size: 18px"></span></p><p style="text-align: center"><span style="font-size: 18px"><img src="https://vietjack.com/csharp/images/generic.PNG" alt="" class="fr-fic fr-dii fr-draggable " data-size="" style="" /></span></p><p></p><p style="text-align: right"><span style="font-size: 18px">Nguồn: Sưu tầm</span></p></blockquote><p></p>
[QUOTE="uocmo_kchodoi, post: 177639, member: 165510"] [URL='https://vnkienthuc.com/forums/code.377/'][SIZE=5]Generic [/SIZE][/URL][SIZE=5]là 1 tính năng mới trong .NET Framework 2.0 và và được tích hợp sâu trong Common Language Runtime (CLR). Trong .NET Framework, Generic được giới thiệu là khái niệm về các kiểu tham số và được dùng để thiết kế class và phương thức nhằm để trì hoãn chỉ ra kiểu dữ liệu cho đến khi lớp hoặc phương thức được khai báo hoặc khởi tạo. [/SIZE] [CENTER][SIZE=5][ATTACH=full]3132._xfImport[/ATTACH][/SIZE][/CENTER] [SIZE=5] Ví dụ, bằng cách sử dụng tham số T là tham số chung, bạn có thể tạo 1 class duy nhất mà khi tham chiếu tới, bạn sẽ không gặp bất kỳ lỗi nào xảy ra trong lúc runtime khi ép kiểu hoặc boxing (chuyển giá trị từ value type sang reference type) [B]Sự ra đời của Generic[/B] Rất nhiều người trong chúng ta [/SIZE][URL='https://vnkienthuc.com/threads/tim-hieu-ve-lop-bitarray-trong-c.77384/'][SIZE=5]sử dụng generic [/SIZE][/URL][SIZE=5]mà không biết rằng nó là generic. Ví dụ, khi muốn tạo 1 danh sách các học sinh, ta thường viết: [I][COLOR=#5900b3]//Một list chứa các object là Student[/COLOR][/I] [I][COLOR=#5900b3]List<Student> students = new List<Student>();[/COLOR][/I] [I][COLOR=#5900b3]students.Add(new Student()); //Code đúng[/COLOR][/I] [I][COLOR=#5900b3]students.Add(new Car()); //Compile lỗi[/COLOR][/I] [I][COLOR=#5900b3]//Lấy học sinh đầu tiên.[/COLOR][/I] [I][COLOR=#5900b3]//Compiler tự hiểu kết quả là Student[/COLOR][/I] [I][COLOR=#5900b3]Student first = students.First();[/COLOR][/I] Generics ở trong 2 dấu ngoặc nhọn đấy bạn <>. Để dễ hiểu, ta hãy quay lại thời .NET 1.0, khi generic chưa xuất hiện: [I][COLOR=#5900b3]//Không có generic[/COLOR][/I] [I][COLOR=#5900b3]//Một list chứa các object[/COLOR][/I] [I][COLOR=#5900b3]List students = new List();[/COLOR][/I] [I][COLOR=#5900b3]students.Add(new Student()); //Compile bình thường[/COLOR][/I] [I][COLOR=#5900b3]students.Add(new Car()); //Compile bình thường[/COLOR][/I] [I][COLOR=#5900b3]//Lấy object đầu tiên, phải ép kiểu sang Student[/COLOR][/I] [I][COLOR=#5900b3]Student first = (Student)students.First();[/COLOR][/I] Không có generic, compiler không thể check lỗi lúc compiler. Do đó, ở dòng 2, ta có thể thêm 1 object Car và list gồm các object Student. Khi lấy 1 phần tử ra, ta cũng phải ép kiểu, vì compiler chỉ hiểu nó là 1 object. Vì những lý do đó, generic đã được thêm vào ở .NET 2.0. [B]Tác dụng của generic:[/B][/SIZE] [LIST] [*][SIZE=5]Giúp tái sử dụng code. Ví dụ: Ta chỉ cần viết class List<T>, T ở đây có thể là bất kì class gì.[/SIZE] [*][SIZE=5]Hỗ trợ compiler bắt lỗi trong quá trình compiler (Hạn chế được tình trạng như dòng 2).[/SIZE] [*][SIZE=5]Không còn phải ép kiểu từ object.[/SIZE] [/LIST] [SIZE=5][B]Ví dụ:[/B] Bạn tạo hai lớp có tên lần lượt là TestGeneric, TestCsharp như sau: Lớp TestGeneric: [I][COLOR=#5900b3]using System;[/COLOR][/I] [I][COLOR=#5900b3]using System.Collections.Generic;[/COLOR][/I] [I][COLOR=#5900b3]namespace VietJackCsharp[/COLOR][/I] [I][COLOR=#5900b3]{[/COLOR][/I] [I][COLOR=#5900b3] class TestGeneric <T>[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] private T[] array;[/COLOR][/I] [I][COLOR=#5900b3] public TestGeneric(int size)[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] array = new T[size + 1];[/COLOR][/I][/SIZE] [SIZE=5][I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3] public T getItem(int index)[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] return array[index];[/COLOR][/I] [I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3] public void setItem(int index, T value)[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] array[index] = value;[/COLOR][/I] [I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3]}[/COLOR][/I] Lớp TestCsharp: [I][COLOR=#5900b3]using System;[/COLOR][/I] [I][COLOR=#5900b3]using System.Collections;[/COLOR][/I] [I][COLOR=#5900b3]namespace VietJackCsharp[/COLOR][/I] [I][COLOR=#5900b3]{[/COLOR][/I] [I][COLOR=#5900b3] class TestCsharp[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] static void Main(string[] args)[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] Console.WriteLine("Vi du minh hoa Generic trong C#");[/COLOR][/I] [I][COLOR=#5900b3] Console.WriteLine("-------------------------------------");[/COLOR][/I] [I][COLOR=#5900b3] [/COLOR][/I] [I][COLOR=#5900b3] //khai bao mot mang cac so nguyen[/COLOR][/I] [I][COLOR=#5900b3] TestGeneric<int> intArray = new TestGeneric<int>(5);[/COLOR][/I] [I][COLOR=#5900b3] //thiet lap cac gia tri[/COLOR][/I] [I][COLOR=#5900b3] for (int c = 0; c < 5; c++)[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] intArray.setItem(c, c * 5);[/COLOR][/I] [I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3] //lay va hien thi cac gia tri[/COLOR][/I] [I][COLOR=#5900b3] for (int c = 0; c < 5; c++)[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] Console.Write(intArray.getItem(c) + " ");[/COLOR][/I] [I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3] Console.WriteLine();[/COLOR][/I] [I][COLOR=#5900b3] //khai bao mot mang ky tu[/COLOR][/I] [I][COLOR=#5900b3] TestGeneric<char> charArray = new TestGeneric<char>(5);[/COLOR][/I] [I][COLOR=#5900b3] //thiet lap gia tri[/COLOR][/I] [I][COLOR=#5900b3] for (int c = 0; c < 5; c++)[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] charArray.setItem(c, (char)(c + 97));[/COLOR][/I] [I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3] //lay va hien thi cac gia tri[/COLOR][/I] [I][COLOR=#5900b3] for (int c = 0; c < 5; c++)[/COLOR][/I] [I][COLOR=#5900b3] {[/COLOR][/I] [I][COLOR=#5900b3] Console.Write(charArray.getItem(c) + " ");[/COLOR][/I] [I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3] Console.WriteLine();[/COLOR][/I] [I][COLOR=#5900b3] [/COLOR][/I] [I][COLOR=#5900b3] Console.ReadKey();[/COLOR][/I] [I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3] }[/COLOR][/I] [I][COLOR=#5900b3]}[/COLOR][/I] Nếu bạn không[/SIZE][URL='https://vnkienthuc.com/threads/tim-hieu-ve-lop-hashtable-trong-c.77360/'][SIZE=5] sử dụng lệnh Console[/SIZE][/URL][SIZE=5].ReadKey(); thì chương trình sẽ chạy và kết thúc luôn (nhanh quá đến nỗi bạn không kịp nhìn kết quả). Lệnh này cho phép chúng ta nhìn kết quả một cách rõ ràng hơn. Biên dịch và chạy chương trình C# trên sẽ cho kết quả sau: [/SIZE] [CENTER][SIZE=5][IMG]https://vietjack.com/csharp/images/generic.PNG[/IMG][/SIZE][/CENTER] [SIZE=5][/SIZE] [RIGHT][SIZE=5]Nguồn: Sưu tầm[/SIZE][/RIGHT] [/QUOTE]
Tên
Mã xác nhận
Gửi trả lời
CÔNG NGHỆ
Công Nghệ Thông Tin
Code
Tìm hiểu về Generic trong C#
Top