C# 0 The Complete Reference


NonGen  instance variable  ob



Download 4,07 Mb.
Pdf ko'rish
bet632/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   628   629   630   631   632   633   634   635   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

NonGen

 instance variable 



ob

 is obtained by 



ShowType( )

:

Console.WriteLine("Type of ob is " + ob.GetType());



Recall from Chapter 11 that 

object

 defines several methods that are available to all data types. 

One of these methods is 

GetType( )

, which returns a 



Type

 object that describes the type of 

www.freepdf-books.com



502

 

P a r t   I :  



T h e   C #   L a n g u a g e

the invoking object at runtime. Thus, even though the type of 



ob

 is specified as 



object

 in the 


program’s source code, at runtime, the actual type of object being referred to is known. This 

is why the CLR will generate an exception if you try an invalid cast during program execution.



A Generic Class with Two Type Parameters

You can declare more than one type parameter in a generic type. To specify two or more 

type parameters, simply use a comma-separated list. For example, the following 

TwoGen

class is a variation of the 



Gen

 class that has two type parameters:

// A simple generic class with two type parameters: T and V.

using System;

class TwoGen {

  T ob1;


  V ob2;

  // Notice that this constructor has parameters of type T and V.

  public TwoGen(T o1, V o2) {

    ob1 = o1;

    ob2 = o2;

  }


  // Show types of T and V.

  public void showTypes() {

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

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

  }

  public T getob1() {



    return ob1;

  }


  public V GetObj2() {

    return ob2;

  }

}

// Demonstrate two generic type parameters.



class SimpGen {

  static void Main() {

    TwoGen tgObj =

      new TwoGen(119, "Alpha Beta Gamma");

    // Show the types.

    tgObj.showTypes();

    // Obtain and show values.

    int v = tgObj.getob1();

    Console.WriteLine("value: " + v);

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   628   629   630   631   632   633   634   635   ...   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