АкушерствоАнатомияАнестезиологияВакцинопрофилактикаВалеологияВетеринарияГигиенаЗаболеванияИммунологияКардиологияНеврологияНефрологияОнкологияОториноларингологияОфтальмологияПаразитологияПедиатрияПервая помощьПсихиатрияПульмонологияРеанимацияРевматологияСтоматологияТерапияТоксикологияТравматологияУрологияФармакологияФармацевтикаФизиотерапияФтизиатрияХирургияЭндокринологияЭпидемиология

Creating generic classes in C#

Прочитайте:
  1. Classes in C#.
  2. Classes of Supply
  3. Classes' data members in C#.
  4. Classes' function members in C#.
  5. Extinction of Different Classes of Fires
  6. Generics in C#.
  7. NET framework classes.
  8. Not required to assign the generic type with the method call. The generic method can be invoked as simply
  9. Partial classes in C#.

Def: Generics introduce to the.NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code. Generic types are used to maximize code reuse, type safety, and performance.

Generic classes encapsulate operations that are not specific to a particular data type. The most common use for generic classes is with collections like linked lists, hash tables, stacks, queues, trees, and so on. Operations such as adding and removing items from the collection are performed in basically the same way regardless of the type of data being stored.When creating generic classes, important considerations include the following:

a. As a rule, the more types we can parameterize, the more flexible and reusable your code becomes. However, too much generalization can create code that is difficult for other developers to read or understand.

b. A good rule is to apply the maximum constraints possible that will still let you handle the types you must handle.

c. Whether to factor generic behavior into base classes and subclasses.Because generic classes can serve as base classes, the same design considerations apply here as with non-generic classes. See the rules about inheriting from generic base classes later in this topic.

d. Whether to implement one or more generic interfaces.

class BaseNode { }

class BaseNodeGeneric<T> { }

 

// concrete type

class NodeConcrete<T>: BaseNode { }

 

//closed constructed type

class NodeClosed<T>: BaseNodeGeneric<int> { }

 

//open constructed type

class NodeOpen<T>: BaseNodeGeneric<T> { }

36. Generics features in C#.


Дата добавления: 2015-09-18 | Просмотры: 585 | Нарушение авторских прав



1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |



При использовании материала ссылка на сайт medlec.org обязательна! (0.002 сек.)