1/75
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Delegates
A class in .NET that encapsulates a method and holds a reference to a method.
delegate keyword
Used in declaring a delegate on a class.
Syntax for Delegate Declaration
Instantiation of Delegate
Use the new keyword associated with the method to create an instance.
Generic Delegates
Delegates that are not bound to any specific type and can reference methods of different types.
Difference between Delegate and Interface
Delegates have no implementation, while interfaces can implement methods.
Event
A member of a class that is fired whenever a specific action takes place.
Event Handlers
Methods that are invoked when an event occurs.
Adding an Event
Use the syntax eventname += delegateinstance.
Removing Event Subscription
Use the remove accessor to unregister a subscription.
Collections
Groups of objects that include lists, linked lists, dictionaries, and arrays.
Standard Collections
Found in the System.Collections namespace.
Generic Collections
Found in the System.Collections.Generic namespace.
ArrayList
A collection class known for an ordered collection of objects that is dynamic.
Hashtable
Stores key-value pairs where the key represents the value in the collection.
SortedList
A combination of ArrayList and Hashtable that stores key-value pairs sorted by key.
Capacity (SortedList)
Gets or sets the capacity of the SortedList.
Count (SortedList)
Gets the count of the number of elements in the SortedList.
Item (SortedList)
Gets and sets the value associated with a specific key in the SortedList.
Keys (SortedList)
Holds the keys in the SortedList.
Values (SortedList)
Holds the values in the SortedList.
Add method (SortedList)
Adds an item with the specified key and value into the SortedList.
Clear method (SortedList)
Removes all the items in the SortedList.
ContainsKey method (SortedList)
Returns true if the SortedList contains the specified key.
ContainsValue method (SortedList)
Returns true if the SortedList contains the specified value.
GetByIndex method (SortedList)
Returns the value of the specified index.
GetKey method (SortedList)
Returns the key of the specified index.
Remove method (SortedList)
Removes the element with the specified key from the SortedList.
RemoveAt method (SortedList)
Removes an element at the specified index in the SortedList.
Stack
Represents a Last In, First Out (LIFO) collection of objects.
Queue
Represents a First In, First Out (FIFO) collection of objects.
IEnumerable interface
Allows looping through elements in a collection.
ICollection interface
Determines the number of elements in a collection and can copy them into an array.
IDictionary interface
Provides a list of elements accessible via a key or value.
Generics
Allows code reuse across different types by creating a template with placeholder types.
System.Collections.Generic namespace
Contains several generic collection classes.
List
A generic collection that provides an efficient and dynamically allocated array.
Add() method (List
Adds items to the end of a list.
Remove() method (List
Removes the specified item from the list.
IndexOf() method (List
Checks for the specified element and returns its index value.
Sort() method (List
Sorts elements in the list.
Queue
A generic collection representing a FIFO collection of objects.
Enqueue() method (Queue
Adds an element to the end of the queue.
Peek() method (Queue
Returns the element at the beginning of the queue without removing it.
Dequeue() method (Queue
Removes and returns the value at the beginning of the queue.
Stack
A generic collection that represents a LIFO collection of instances.
Push() method (Stack
Adds an element at the top of the stack.
Peek() method (Stack
Returns the element at the top of the stack without removing it.
Pop() method (Stack
Removes and returns the value at the top of the stack.
Difference: Delegate Implementation
Delegates have no implementation while interfaces can implement methods associated with them.
Usage of Delegates
Used in classes where multiple implementations of methods are needed.
Performance of Delegates vs Interfaces
Delegates are faster to execute but slower to acquire, interfaces are slower to execute but faster to acquire.
Subscription to Events
Registered using add accessor for events.
Removing Subscriptions to Events
Done using the remove accessor associated with the event.
ArrayList vs Static Array
ArrayList is dynamic; a static array has a fixed size.
Hashtable Key Requirement
Keys must be specified to access corresponding values in Hashtable.
SortedList Access Requirements
Key or index value must be specified to access values in SortedList.
SortedList Method: Add
Adds a key-value pair to the SortedList.
SortedList Method: RemoveAt
Specifies index to remove the element in the SortedList.
Stack Behavior
LIFO, utilizing push and pop operations.
Queue Characteristics
FIFO, utilizing enqueue and dequeue operations.
IEnumerable Functionality
Provides iteration capabilities for collections.
Generics Purpose
To enhance code reusability by specifying data types at runtime.
List
Can dynamically grow or shrink based on object quantity.
Generic Method Example: Add() in List
nameOfStud.Add("Rose"); to add a student.
Generic Method Example: Remove() in List
nameOfStud.Remove("Mike"); to remove a specified student.
Generic Method Example: IndexOf() in List
Console.WriteLine(nameOfStud.IndexOf("Rose")); to find index.
Generic Method Example: Sort() in List
nameOfStud.Sort(); to sort the student names.
Queue
Queue
Queue
ageQueue.Enqueue(18); to add an age to the queue.
Queue
ageQueue.Peek(); to get the first age without removing.
Queue
int getValue = ageQueue.Dequeue(); to remove and get the first age.
Stack
Stack
Stack
ageStack.Push(18); to add age to the top of the stack.
Stack
int getValue = ageStack.Peek(); to get the top age without removing.
Stack
int getValue = ageStack.Pop(); to remove and get the top age.