Wei-Meng Lee - C# 2008 Programmer's Reference

Здесь есть возможность читать онлайн «Wei-Meng Lee - C# 2008 Programmer's Reference» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2009, ISBN: 2009, Издательство: Wiley Publishing, Inc., Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

C# 2008 Programmer's Reference: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «C# 2008 Programmer's Reference»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

C# 2008 Programmers Reference provides a concise and thorough reference on all aspects of the language. Each chapter contains detailed code samples that provide a quick and easy way to understand the key concepts covered.

C# 2008 Programmer's Reference — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «C# 2008 Programmer's Reference», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

for (int i = 0; i < _pointer; i++) {

if (_elements[i].CompareTo(keyword) == 0) {

found = true;

break;

}

}

return found;

}

public bool Empty {

get {

return (_pointer <= 0);

}

}

public static MyStack operator +

(MyStack stackA, MyStack stackB) {

while (IstackB.Empty) {

T item = stackB.Pop();

stackA.Push(item);

}

return stackA;

}

}

The +operator takes in two operands — the generic MyStackobjects. Internally, you pop out each element from the second stack and push it into the first stack. The Emptyproperty allows you to know if a stack is empty.

To print out the elements of stack1after the joining, use the following statements:

stack1 += stack2;

while (!stack1.Empty)

Console.WriteLine(stack1.Pop());

Here's the output:

C

D

B

A

Generic Delegates

You can also use generics on delegates. The following class definition contains a generic delegate, MethodDelegate:

public class SomeClass {

public delegate void MethodDelegate(T t);

public void DoSomething(T t) {

}

}

When you specify the type for the class, you also need to specify it for the delegate:

SomeClass sc = new SomeClass();

SomeClass.MethodDelegate del;

del = new SomeClass.MethodDelegate(sc.DoSomething);

You can make direct assignment to the delegate using a feature known as delegate inferencing, as the following code shows:

del = sc.DoSomething;

Generics and the .NET Framework Class Library

The .NET Framework class library contains a number of generic classes that enable users to create strongly typed collections. These classes are grouped under the System.Collections.Genericnamespace (the nongeneric versions of the classes are contained within the System.Collectionsnamespace). The following tables show the various classes, structures, and interfaces contained within this namespace.

The following table provides a look at the classes contained within the System.Collections.Genericnamespace.

Class Description
Comparer<(Of <(T>)>) Provides a base class for implementations of the IComparer<(Of <(T>)>)generic interface.
Dictionary<(Of <(TKey, TValue>)>) Represents a collection of keys and values.
Dictionary<(Of <(TKey, TValue>)<)..::.KeyCollection Represents the collection of keys in a Dictionary<(Of <(TKey, TValue>)>). This class cannot be inherited.
Dictionary<(Of <(TKey, TValue>)>)..::.ValueCollection Represents the collection of values in a Dictionary<(Of <(TKey, TValue>)>). This class cannot be inherited.
EqualityComparer<(Of <(T>)>) Provides a base class for implementations of the IEqualityComparer<(Of <(T>)>)generic interface.
HashSet<(Of <(T>)>) Represents a set of values.
KeyedByTypeCollection<(Of <(TItem>)>) Provides a collection whose items are types that serve as keys.
KeyNotFoundException The exception that is thrown when the key specified for accessing an element in a collection does not match any key in the collection.
LinkedList<(Of <(T>)>) Represents a doubly linked list.
LinkedListNode<(Of <(T>)>) Represents a node in a LinkedList<(Of <(T>)>). This class cannot be inherited.
List<(Of <(T>)>) Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.
Queue<(Of <(T<)>) Represents a first-in, first-out collection of objects.
SortedDictionary<(Of <(TKey, TValue>)>) Represents a collection of key/value pairs that are sorted on the key.
SortedDictionary<(Of <(TKey, TValue>)>)..::.KeyCollection Represents the collection of keys in a SortedDictionary<(Of <(TKey, TValue>)>). This class cannot be inherited.
SortedDictionary<(Of <(TKey, TValue>)>)..::.ValueCollection Represents the collection of values in a SortedDictionary<(Of <(TKey, TValue>)>). This class cannot be inherited.
SortedList<(Of <(TKey, TValue>)>) Represents a collection of key/value pairs that are sorted by key based on the associated IComparer<(Of <(T>)>)implementation.
Stack<(Of <(T>)>) Represents a variable size last-in, first-out (LIFO) collection of instances of the same arbitrary type.
SynchronizedCollection<(Of <(T>)>) Provides a thread-safe collection that contains objects of a type specified by the generic parameter as elements.
SynchronizedKeyedCollection<(Of <(K, T>)>) Provides a thread-safe collection that contains objects of a type specified by a generic parameter and that are grouped by keys.
SynchronizedReadOnlyCollection <(Of <(T>)>) Provides a thread-safe, read-only collection that contains objects of a type specified by the generic parameter as elements.

The structures contained within the System.Collections.Genericnamespace are described in the following table.

Structure Description
Dictionary<(Of <(TKey, TValue>)>)..::.Enumerator Enumerates the elements of a Dictionary<(Of <(TKey, TValue>)>)
Dictionary<(Of <(TKey, TValue>)>)..::. KeyCollection..::.Enumerator Enumerates the elements of a Dictionary<(Of <(TKey, TValue>)>)..::.KeyCollection
Dictionary<(Of <(TKey, TValue>)>)..::. ValueCollection..::.Enumerator Enumerates the elements of a Dictionary<(Of <(TKey, TValue>)>)..::.ValueCollection
HashSet<(Of <(T>)>)..::.Enumerator Enumerates the elements of a HashSet<(Of <(T>)>)object
KeyValuePair<(Of <(TKey, TValue>)>) Defines a key/value pair that can be set or retrieved
LinkedList<(Of <(T>)>)..::.Enumerator Enumerates the elements of a LinkedList<(Of <(T>)>)
List<(Of <(T>)>)..::.Enumerator Enumerates the elements of a List<(Of <(T>)>)
Queue<(Of <(T>)>)..::.Enumerator Enumerates the elements of a Queue<(Of <(T>)>)
SortedDictionary<(Of <(TKey, TValue>)>)..::.Enumerator Enumerates the elements of a SortedDictionary<(Of <(TKey, TValue>)>)
SortedDictionary<(Of <(TKey, TValue>)>)..::.KeyCollection..::.Enumerator Enumerates the elements of a SortedDictionary<(Of <(TKey, TValue>)>)..::.KeyCollection
SortedDictionary<(Of <(TKey, TValue>)>)..::.ValueCollection..::. Enumerator Enumerates the elements of a SortedDictionary<(Of <(TKey, TValue>)>)..::.ValueCollection
Stack(<(T>)>)..::.Enumerator Enumerates the elements of a Stack<(Of <(T>)>)

Following are descriptions of the interfaces contained within the System.Collections.Genericnamespace.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «C# 2008 Programmer's Reference»

Представляем Вашему вниманию похожие книги на «C# 2008 Programmer's Reference» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «C# 2008 Programmer's Reference»

Обсуждение, отзывы о книге «C# 2008 Programmer's Reference» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x