C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet625/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   621   622   623   624   625   626   627   628   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

N

OTE

N

OTE

A Warning to C++ and Java Programmers:  Although C# generics are similar to templates 

in C++ and generics in Java, they are not the same as either. In fact, there are some fundamental 

differences among these three approaches to generics. If you have a background in C++ or Java, it 

is important to not jump to conclusions about how generics work in C#.

A Simple Generics Example

Let’s begin with a simple example of a generic class. The following program defines two 

classes. The first is the generic class 

Gen

, and the second is 



GenericsDemo

, which uses 



Gen

.

// A simple generic class.



using System;

// In the following Gen class, T is a type parameter

// that will be replaced by a real type when an object

// of type Gen is created.

class Gen {

  T ob; // declare a variable of type T

  // Notice that this constructor has a parameter of type T.

  public Gen(T o) {

    ob = o;

  }


  // Return ob, which is of type T.

  public T GetOb() {

    return ob;

  }


  // Show type of T.

  public void ShowType() {

    Console.WriteLine("Type of T is " + typeof(T));

  }


}

// Demonstrate the generic class.

class GenericsDemo {

  static void Main() {

    // Create a Gen reference for int.

    Gen iOb;

    // Create a Gen object and assign its reference to iOb.

    iOb = new Gen(102);

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   621   622   623   624   625   626   627   628   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish