Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

TQ – Generics

Thèmes des Questions – C# (C Sharp)



Indiquez quels sont les affichages du programme de gauche, n’utiliser l’exécution de µ-EdiC# que si vous vous ne trouvez pas.

Explicitez les résultats affichés.

using System;
 class Exercice
 {
 public static void Main( ) 
 {
 ClassGeneric obj = new ClassGeneric  ( );
 ClasseA objA = obj.meth1< ClasseA >( );
 ClasseB objB_1 = obj.meth1< ClasseB >( );
 ClasseB objB_2 = obj.meth2< ClasseB >( );
 Console.WriteLine( "objA.prop = "+objA.prop);
 Console.WriteLine( "objB_meth1.prop = "+objB_1.prop);
 Console.WriteLine( "objB_meth2.prop = "+objB_2.prop);
 Console.ReadLine( );
 }
 }
 class ClasseA
 {
 private int a=100;
 public virtual int prop
 {
 get
 {
 return a;
 }
 set
 {
 a = value;
 }
 }
 }
 class ClasseB : ClasseA
 {
 public override int prop
 {
 get
 {
 return base.prop*10;
 }
 }
 }
 class ClassGeneric 
 {
 public T meth1 < T >( )where T  :  ClasseA, new( )
 {
 T  x = new T( );
 x.prop+=2;
 return x;
 }
 public T meth2 < T >( )where T  :  ClasseB, new( )
 {
 T  x = new T( );
 x.prop+=2;
 return x;
 }
 }

Comments are closed, but trackbacks and pingbacks are open.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More