C# Flashcards

(100 cards)

1
Q

STRUCT

A

IS STORED IN STACK MEMORY; OPTIMIZED & EFFICIENT; ONLY USED FOR ENCAPSULATING SIMPLE DATA, LITTLE TO NO BEHAVIOR. GENERALLY SIMPLE DATATYPE OR PROPERTIES &
VERY SIMPLE FUNCTION OF METHODS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

DICTIONARY

A

Dictionary − Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

HASHSETS

A

~UNORDERED COLLECTIONS OF UNIQUE ELEMENTS; DUPLICATES NOT ALLOWED
~DYNAMIC COLLECTION, but ONLY STORE SAME TYPES OF ELEMENTS
~SET OPERATIONS- INTERSECTIONS, UNIONS, & DIFFERENCES
HashSet in C# eliminates duplicate strings or elements in an array. In C#, it is an optimized set collection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Properties

A

behave like fields when they are accessed. However, unlike fields, properties are implemented with accessors that define the statements executed when a property is accessed or assigned.

are first class citizens in C#. The language defines syntax that enables developers to write code that accurately expresses their design intent.

{get; set;}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Stack

A
(LIFO):
                                                      Major Operations:
Push - Add element into stack
Pop - Remove an element from TOP
Peek - Retrieve the TOP element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Queue

A
(FIFO):
                                                                                                  Major Operations:
Enqueue - Add element into Queue
Dequeue - Remove element from Queue
Peek - Retrieve the TOP element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Abstract methods

A

~implicitly a virtual method.
~declarations are only permitted in abstract classes
~abstract method declaration provides no actual implementation,
~there is no method body; the method declaration
~ simply ends with a semicolon and there are NO curly braces { } following the signature.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

STATIC

A

~SINGLE COMMAND DETERMINES WHETHER A METHOD OR VARIABLE BELONGS TO A CLASS AS A WHOLE OR A ONLY AS AN INSTANCE

~ANY METHOD OR VARIABLE LABELED ARE AVAILABLE WITHOUT HAVING TO CREATE OBJECTS OF THAT CLASS

~MAIN METHOD ALWAYS LABELED…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

INDEXERS

A

~…FOR COLLECTIONS [ ] (square brackets)
~PROPERTIES FOR VARIABLES { } (curly braces)
~DECLARE USING KEYWORD AND DECLARING ARGUMENTS WITHIN SQUARE BRACKETS [ ]
~SIMILAR TO PROPERTIES; ENABLE INDEX PROPERTIES;
~PROPERTIES REFERENCED USING ONE OR MORE ARGUMENTS
~THE ARGUMENTS PROVIDE AN INDEX INTO SOME COLLECTION OF VALUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

VIRTUAL METHODS

A

~ALLOWS THE METHOD FOR THE BASE CLASS TO BE OVERRIDDEN
~ESSENTIAL FOR METHOD OVERRIDING & POLYMORPHISM
~DOESNT ALLOW METHODS TO BE PRIVATE (CAN’T BE INHERITED)
~A virtual method is used to override specified base class implementation when a runtime object is of the derived type.
~virtual method is declared abstract
can’t use this the virtual modifier with the static, abstract, private, or override modifiers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

ABSTRACT VS. VIRTUAL

A

~ABSTRACT METHOD: NO IMPLEMENTATION MUST OVERRIDE WITH ABSTRACT BECAUSE THERE IS ONLY METHOD DECLARATION BUT NO IMPLEMENTATION
~VIRTUAL METHOD: ALREADY HAS IMPLEMENTATION IN BASE CLASS PROVIDE ABILITY TO OVERRIDE
base keyword; modified method in base class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

ABSTRACT MODIFIER

A

~ENABLES YOU TO CREATE INCOMPLETE IMPLEMENTATION OF WHATEVER YOU APPLIED IT TO & MUST BE IMPLEMENTED IN CLASS
~IMPLICITLY USED BY INTERFACES
~EXPLICITLY USED BY ABSTRACT CLASSES
~ABSTRACT CLASS & INTERFACE CAN’T BE IINSTANTIATED BUT MEANT TO BE INHERITED/IMPLEMENTED
~ABSTRACT/CONCRETE CLASS CAN IMPLEMENT ONE OR MORE INTERFACES BY WHICH MULTIPLE INHERITANCE IS ACHIEVED BUT THE CLASS CAN ONLY INHERIT ONE CLASS AND ONE OR MORE INTERFACES

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Abstract Method

A

~IMPLICITLY A VIRTUAL METHOD
~DECLARATION ARE ONLY PERMITTED IN ABSTRACT CLASSES
~ DECLARATION PROVIDE NO ACTUAL INPLEMENTATION
~NO METHOD BODY; DECLARATION ENDS W/ SEMICOLON & NO CURLY BRACES FOLLOWING THE SIGNATURE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

6 ACCESS MODIFIERS

A
~PUBLIC 
~PRIVATE 
~PRIVATE PROTECTED 
~PROTECTED 
~PROTECTED INTERNAL
~INTERNAL
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

PUBLIC ACCESS MODIFIER

A

~ACCESSED BY ANY OTHER CODE IN THE SAME
~ASSEMBLY OR ANOTHER ASSEMBLY THAT REFERENCES IT
CONTROLLED BY THE ACCESSIBILITY ITSELF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

PRIVATE ACCESS MODIFIER

A

~CAN ONLY BE ACCESSED BY CODE IN SAME CLLASS OR STRUCT
~ASSESSED BY CLASS ONLY
*hint: “curly brace boundary”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

PRIVATE PROTECTED ACCESS MODIFIERS

A

CAN BE ACCESSED BY TYPES FROM CLASS THAT ARE DECLARED WITHIN CONTAINING ASSEMBLY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

PROTECTED ACCESS MODIFIER

A

TYPE OR MEMBER CAN BE ACCESSED ONLY BY THE CODE IN THE SAME CLASS, OR IN A CLASS DERIVED FROM THE CLASS CAN BE ACCESSED BY THE FOLLOWING:
~CLASS
~CHILD WITHIN ASSEMBLY
~ONLY CHILD IN & OUTSIDE ASSEMBLY

USED COMMONLY WITH INHERITANCE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

PROTECTED INTERNAL ACCESSE MODIFIERS

A

~CAN BE ACCESSED BY ANY CODE IN THE ASSEMBLY IN WHICH ITS DECLARED, OR FROM WITHIN DERIVED CLASS IN ANOTHER ASSEMBLY
~CAN BE ACCESSED OUTSIDE ASSEMBLY ONLY IN CHILD CLASS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

INTERNAL ACCESS MODIFIER

A

~TYPE OR MEMBER CAN BE ACCESSED BY ANY CODE IN THE SAME ASSEMBLY BUT NOT FROM ANOTHER ASSEMBLY; CODE FROM A PART OF THE SAME COMPILATION
~ACCESSED BY NON-DERIVED CLASS IN SAME ASSEMBLY
sn: Kinda private; scope is entire object declared in

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

DEFINE: ACCESS MODIFIERS

A

~PERMISSION LEVELS OTHER CLASSES HAVE TO THIS METHOD, CLASS OR VARIABLE;
~METHODS AND VARIABLES SUPPORT ALL ACCESS MODIFIERS
~WHEN YOU DECLARE A VARIABLE OR METHOD YOU SPECIFY THE MODIFIER IN FRONT
~CLASSES ONLY SUPPORT PUBLIC OR DEFAULT LEVELS OF ACCESS
sn: common pattern to create Private variables and Public accessor methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

STATIC MODIFIER

A

to declare a static member, which belongs to the type itself rather than to a specific object.
~can be used with classes, fields, methods, properties, operators, events, and constructors, but it cannot be used with indexers, finalizers, or types other than classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

A CONSTANT

A

or type declaration is implicitly a static member.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

CONSTRUCTOR

A

is used to initialize the state of an object.
must not have a return type.
is invoked implicitly.
The Java compiler provides a default constructor if you don’t have any constructor in a class.
The constructor name must be same as the class name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Advantages of OOPs over Procedure Oriented Programming
~OOPs makes development and maintenance easier whereas in a procedure-oriented programming language it is not easy to manage if code grows as project size increases. ~OOPs provides data hiding whereas in a procedure-oriented programming language a global data can be accessed from anywhere.
26
Collections in C#
``` ~classes are specialized classes for data storage and retrieval. These classes provide support for stacks, queues, lists, and hash tables. Most collection classes implement the same interfaces. ~classes serve various purposes, such as allocating memory dynamically to elements and accessing a list of items on the basis of an index etc. These classes create collections of objects of the Object class, which is the base class for all data types in C#. ```
27
System.Collection namespace
ArrayList HashTable Stack Queue
28
NULLABLE
~MAKES DATATYPES OPTIONAL ~DENOTES BY USING '?' ~ENABLES OTION FOR DATATYPE TO HOLD A NULL VALUE ~USEFUL FOR COMPILER TO HELP OUT, CONSIDER GIVING A NULL... bool? x -means 'x' can hold true, false, or null value int? y -means 'y' can hold numbers or null string? i- 'i' can hold characters or null
29
NON ACCESS MODIFIERS
``` remember....V.A.R.O.S. ~VIRTUAL ~ABSTRACT ~READONLY ~OVERRIDE ~STATIC ```
30
REFERENCE VARIABLE
~USE A CLASS AS A TYPE THEY CAN HOLD THE ADDRESS OF ANY OBJECT THAT IS AN INSTANCE OF THAT CLASS Dog myDog= new Dog( ); ~OBJECTS ARE STORED IN HEAP MEMORY & THEIR ADDESSES ARE STORED IN.....? ~SOMEWHAT LIKE A MASK OVER OBJECTS CODE ex: Polymorphism
31
VALUE TYPES
~STORE IN DIRECT VALUE; ~STORED IN MEMORY STACK ~STACK IS ALWAYS FASTER TO RETRIEVE DATA THAN HEAP ~SET OF MEMORY SET ASIDE FOR IT TO OCCUPY ex predefined: (int, long, short, byte, data type, char) structs - like a class but gets stored in the stack for memory retrieval efficiency enums - defines a set of named integral constants
32
REFERENCE TYPES
~DATATYPES STORED IN THE HEAP & REFERENCE VARIABLES STORED IN THE STACK ~THE ACTUAL OBJECT ITSELF IS STORED IN THE HEAP ~RETRIEVING A VALUE FROM HEAP IS AN EXPENSIVE PROCESS ~HEAP IS DYNAMICALLY CHANGING ex predefined: string, arrays, collections, classes, interfaces, delegates
33
SIGNIFICANCE OF OVERRIDING
ALLOWS FOR THE CHILD CLASSES TO PROVIDE NEW IMPLEMENTATION FOR THEIR PARENT FUNCTIONALITY hint: useful for polymorphic references
34
METHOD OVERLOADING
~CREATION OF METHODS WITH THE SAME NAME AS ANOTHER IN THE SAME CLASSBUT DIFFERS IN PARAMETERS (order number, type) ~EXAMPLE OFSTATIC/ COMPILE TIME POLYMORPHISM; ~METHOD WITH SAME NAME BEHAVES DIFFERENTLY BASED ON SIGNATURES(parameters) Signatures can be different in 3 ways: Number of parameters. Datatype of parameters. Sequence of parameters.
35
OVERRIDE METHODS or METHOD OVERRIDING
~METHOD OVERRIDING IS AN EXAMPLE OF RUNTIME POLYMORPHISM; WHICH IS REDEFINIG THE METHOD OF THE PARENT CLASS INTO CHILD CLASS ~TO OVERRIDE A METHOD YOU MUST FIRST HAVE A METHOD ON A PARENT CLASS. IN THE CHILD CLASS YOU NEED TO SPECIFY A METHOD OF THE SAME SIGNATURE ``` ~It is also known as dynamic/runtime polymorphism. Redefining the method of base class in child class. ``` ~necessary to make a method overridable by using abstract or virtual keyword in base class In child class use the keyword override to override these methods.
36
OBJECT ORIENTED PROGRAMMING (OOP)
~PROGRAMMING PARADIGGM TO MAKE PROGRAMS BETTER ~ORGANIZED INTO CLASSES ACCESSED BY OBJECTS suited for large complex projects ; actively updated ~BENEFITS: READABILITY, REUSABILITY (inheritance), SCALABILITY, & EFFICIENCY ~STRUCTUE "building blocks": CLASSES, OBJECTS, METHODS, ATTRIBUTES ~CLASSES w/ ATTRIBUTES/ PROPERTY ~TYPES w/ BEHAVIORS AND OPERATIONS (methods) ~OBJECTS ARE AN INSTANCE OF A CLASS, ALLOCATED MEMORY ~WHEN CLASS INSTANTIATED OBJECTS COMES TO LIFE ~ATTRIBUTES CAN BE STATIC OR DYNAMIC
37
WHAT ARE THE PILLARS
``` "A PIE" ~ABSTRACTION ~POLYMORPHISM ~INHERITANCE ~ENCAPSULATION ```
38
ABSTRACTION
occurs when you simplify a complex thought or complex system ~like a template ~shows only essential features of the program instead of unnecessary details ~in c# it is achieved by "abstract" classes and interfaces hint ex: "tax system" ... the black box is the functionality
39
ENCAPSULATION
"WRAPPING OF DATA" ~methods enclose data field ~class/type encloses a method ~namespace encapsulates the type "DATA HIDING" ~provide protection from outside members/world -use access modifiers to provide levels of access
40
INHERITANCE
~GIVE ACCESS TO THE VARIABLES AND METHODS OF ONE CLASS TO ANOTHER (extends a type so its properties & behaviors can be extended/branched further) ~Child and Parent relationship "is-a(n)" relationship ~a class can only extend one other class ``` ~Single = A>B ~Multi-Level = A>B>C ~Hierarchal = "FAMILY TREE" ~Multiple Inheritance (A,B...) >C ~2 or more parents ~Hybrid (all of the above) ``` C# doesn't support MULTIPLE OR HYBRID INHERITANCE
41
POLYMORPHISM
``` ~ABILITY TO IMPLEMENT INHERITED PROPERTIES OR METHODS IN DIFFERENT WAYS ACROSS MULTIPLE ABSTRACTIONS "is a(n)" relationship; when one class extends another, an instance of that child class is also an instance of the parent class ex: dog is an instance of an animal sn: if one class can be described as an example or subtype of another class than it can probably inherit from it ```
42
TYPES OF POLYMORPHISIM
~STATIC/ COMPILE TIME or DYNAMIC/ RUNTIME COMPILE TIME POLYMORPHISM = METHOD OVERLOADING (remember the "L's") RUNTIME = METHOD OVERRIDINIG (remember the "R's")
43
DIFFERENCE BETWEEN PROTECTED AND PRIVATE PROTECTED ACCESS MODIFIERS IN C#
THE ACCESSIBILITY IS BASED ON THE ASSEMBLY WHICH MATTERS IN PRIVATE PROTECTED PRIVATE PROTECTED METHODS CAN BE ACCESSED INSIDE SAME ASSEMBLY private protected is that it must live in the same assembly to be accessible: private: The type or member can be accessed only by code in the same class or struct . protected: The type or member can be accessed only by code in the same class , or in a class that is derived from that class .
44
DEFAULT MODIFIERS
"TYPES" (ex: class) is INTERNAL | "TYPES MEMBERS" (ex: methods and variables) is PRIVATE
45
INTERFACE
~USED TO GUARENTEE THE AVAILABILITY OF METHODS IN IMPLEMENTING CLASS ~ALL METHODS ARE PUBLIC ABSTRACT ~ALL VARIABLES ARE PUBLIC, STATIC, FINAL these tools declare specific behavior for objects ~ABSTRACT ENTITY; WRITTEN SIMILAR TO CLASSES ~IMPLEMENT KEYWORD IN CLASS DECLARATION AFTER EXTENDING CLASS ~MAKES COMPILER ENFORCED CONTRACTS. ~A CLASS THAT IMPLEMENTS AN INTERFACE MUST PROVIDE AN IMPLEMENTATION FOR EVERY INTERFACE METHOD OR BE AN ABSTRACT CLASS because the implementing class would till have an abstract method & your not allowed to have a concrete class that doesn't implement every method it declares
46
INTERFACE & INHERITANCE
~A CLASS CAN ONLY EXTEND ONE OTHER CONCRETE OR ABSTRACT CLASS BUT CAN IMPLEMENTS MULTIPLE INTERFACES ~INTERFACES EXTEND OTHER INTERFACES WITH NO LIMITS TO QUANTITY, BUT CAN'T EXTEND OTHER CLASSES ~NON-TRADITIONAL INHERITANCE; ~said to have "type" inheritance. A class that implements an interface is polymorphically considered an instance of the interface " is- a(n)" relationship when an interface is implemented interface methods do not have implementations & interface variables are static, so no states or behaviors are inherited ~AN INTERFACE DESCRIBES WHAT BEHAVIORS (verb) A CLASS SHOULD HAVE; it provides none of its own ~
47
USING STATEMENT
~HELPS COMPILER RESOLVE NAMESPACES BUT REQUIRE FEWER KEYSTROKES ~INSTRUCTS COMPILER WHERE TO LOOK FOR REFERENCES TO CLASSES
48
ERRORS
An Error "indicates serious problems that a reasonable application should not try to catch." A serious problem that for the most part cannot be handled by the developer -They are fatal to the program at runtime Ex: A stack overflow error and that usually occurs when your computer has run out of memory to store information 3 types of errors ~Usage error - error in your program logic and can be solve by modifying/restructuring your code ~Program Error - run-time error that cannot be avoided even with a bug-free code (Ex: Your SDK is corrupt and can't compile or translate it to machine code properly) ~System Failures - run-time error that cannot be handled programmatically in a meaningful way (Ex: your ram hardware is faulty)
49
EXCEPTIONS
~are problems which can occur at runtime/compile time ~indicates conditions that a reasonable application might want to catch. ~Exceptions can be generated by the common language runtime (CLR), by .NET or third-party libraries, or by application code. ex: ~ArgumentExceptions ~ArgumentOutOfRangeException SYSTEM EXCEPTIONS: ~NullReferenceException ~InvalidOperationException IO EXCEPTIONS: * DivideByZeroException * OutofMemoryException * StackOverFlowException * IndexOutOfRangeException APPLICATION EXCEPTION: (Anticipated by developer) CustomExceptions
50
EXCEPTION HANDLING & WHY?
~HANDLED GRACEFULLY SO THAT USER IS PROVIDED WITH INFORMATION AS WHY THE APPLICATION IS NOT RESPONDING AS ANTICIPATED WHY: *better user experience *make program robust *log exceptions to learn from the reason and fix them IN C#: TRY, CATCH, FINALLY, THROW(keyword) ; must have at least one catch block or one finally block The catch block will then "catch" that exception and will run instead of its block of code Once an exception occurs in the try block, the flow of control jumps to the first associated exception handler that is present anywhere in the call stack. In C#, the catch keyword is used to define an exception handler. If no exception handler for a given exception is present, the program stops executing with an error message. Don't catch an exception unless you can handle it and leave the application in a known state. Optionally, you can add a finally block that will run regardless if your code throws an exception or not Mostly used to clean up any resources you used in the try blcok
51
I. RUNTIME ERRORS and II. COMPILE TIME ERRORS
I. aka EXCEPTIONS THAT CAUSE THE PROGRAM TO TERMINATE | II. SYNTAX ERRORS
52
GENERIC DATA TYPES
~type-safe at compile time. Because of this, generic collections typically offer better performance. ~Generic collections accept a type parameter when they are constructed and do not require that you cast to and from. ~The "T" you see in documentation is where you put what data type that collection will hold ~All collections provide methods for adding, removing, or finding items in the collection. ~All collections can be enumerated by virtue of Enumerator. ~An enumerator can be thought of as a movable pointer to any element in the collection. ************** LIST ************** SORTED LIST ************** LINKED LIST ************** HASHSETS ************** DICTIONARIES ************** STACK; ************** QUEUE
53
CLS
Common Language Specification It has defined rules and restrictions that every langauge must follow for it to be able to run the .NET framework Essentially a standardization to make sure a language won't do anything that will make it incompatible with .NET framework
54
CTS
Common Type System Provides a library of the basic value data types It is a standardization of data types to ensure every language will follow the same datatype Ex: int in C# is the same 32-bit memory as the int in Visual Basic Helps create Language Interoperability Fancy way of saying .NET has the capability to develop application using two or more programming languages You can create apps using Visual Basic, C#, J# (Java-like language that can run in .NET), etc. NEVER SAY JAVA ITSELF J# IS NOT JAVA
55
CLR
Common Language Runtime implements VES so anything in VES, CLR also has it plus more Essentially, it is .NET's version of VES Run-time environment that provides services that make the development process easier Some servies it includes: Automatic memory management (older languages you have to manually release unused resources) JIT compilation (Just-inTime compilation that involves compliation during execution for optimization) It just means any new compile code gets executed immediately, it doesn't have to wait until your entire code has been compiled to run your app Exception handling support Security
56
Virtual Execution System (VES)
a run-time system of the Common Language Infrastructure CLI which provides an environment for executing managed code.
57
Namespace
Logical grouping of classes that follow a certain theme of functionality To utilize the classes located in a different namespace, you must use the 'using' keyword
58
Assembly
They contain all the files that are actual executables These files will differ depending on what operating system you are using but as for windows, it will be .exe and .dll (dynamic link library) files If you open the auto-generated bin folders, you can file the assembly files located there So main difference with projects are that projects are the .cs files and .csproj and other configurations while assembly is the actual files that gets run since that is what your operating system understands
59
Solution
The final grouping mechanism in that it will group multiple projects as one application They are the final packaging of your application
60
I. read-only - II. write-only III. read-write property
I. with only get block. II. with only set block. III. with both get and set block.
61
A. Boxing & | B. Unboxing
A. ~It is when a value type gets casted into an object Useful if you want a value type to have reference type like functionalities It is implicit conversion ~refers to conversion Value type to reference types. B. ~When you extract the value from an object and convert it into a value type instead It is explicit conversion ~refers to conversion of reference types to value types.
62
IMPLICIT TYPE CONVERSION
Generally, it is when you can convert the type without any data loss Mostly used with numerical datatypes No special syntax needed to write and compiler will do it for you no need to type cast manually/explicitly. ex: byte value can be placed in int; converting an int into a double
63
EXPLICIT TYPE CONVERSION
If there is a risk of losing information, you must perform a Cast Special syntax is needed to write to tell the compiler to do it anyway Casting is denoted with (datatype) type cast it using .Parse(value), Convert.(value). You can have a data loss if its not fitting in the type. The Parse method returns the converted number; the TryParse method returns a boolean value that indicates whether the conversion succeeded, and returns the converted number in an out parameter.
64
ARRAYS
Used to store a datatype and have fixed sizes Zero-based index 0 is the starting position of the array Other arrays you can make: Multidimensional arrays - int[,] ex = new int[4,2]; would create [ [0, 0], [0, 0], [0, 0], [0, 0] ] Jagged arrays - arrays inside of an array are different sizes [ [0, 0, 0], [0, 0], [0, 0, 0], [0, 0 , 0, 0] ]
65
LIST
~Like any array which can grow and shrink dynamically. ~Items in the list can be accessed by index. ~It can accept null as a valid value for reference types and it also allows duplicate elements. ~List class is not sorted by default and elements are accessed by zero-based index. Properties ~Capacity - Gets or sets the total number of elements the internal data structure can hold without resizing. ~Count - Gets the number of elements contained in the List ~Methods: ~Add(T) - Adds an object to the end of the List ~Clear() - Removes all elements from the List ~Insert(index, T) - Inserts an element into the List at the specified index ~Remove(T) - Removes the first occurrence of a specific object from the List ~RemoveAt(index) - Removes the element at the specified index of the List ~Reverse() - Reverses the order of the elements in the List or a portion of it
66
DICTIONARY
It stores key/value pairs | Keys must be Unique
67
SORTED LISTS
It is a sorted list of key/value pairs
68
LINKED LIST
It allows fast inserting and removing of elements. It implements a classic linked list. Each element is separately allocated. Properties Count - Gets the number of nodes actually contained in the LinkedList. First - Gets the first node of the LinkedList. Last - Gets the last node of the LinkedList. Methods AddFirst - Adds a new node or value at the start of the LinkedList. AddLast - Adds a new node or value at the end of the LinkedList. Clear() - Removes all nodes from the LinkedList. Contains(T) - Determines whether a value is in the LinkedList. Remove(LinkedListNode) - Removes the specified node from the LinkedList. Remove(T) - Removes the first occurrence of the specified value from the LinkedList. RemoveFirst() - Removes the node at the start of the LinkedList. RemoveLast() - Removes the node at the end of the LinkedList.
69
**ABSTRACT CLASS VS INTERFACE**
``` An interface defines a contract. Any class or struct that implements that contract must provide an implementation of the members defined in the interface. Abstract class allows you to implement a spectrum of abstraction like full abstraction, partial abstraction etc.... Abstract class allows you to have all types of members. Like you can have data variables and assign values to it and can create methods with definition. But interface can only have methods, properties, events, indexers, which means interfaces cannot have variables or methods with implementation (except C# 8.0 or later version allow you to have static methods with implementation). Abstract class and interface cannot be instantiated but meant to be implemented/inherited. Abstract/Concrete class can implement one or more interfaces by which multiple inheritance is achieved. But class can only inherit from 1 class. A class can inherit 1 class and one or more interfaces. ```
70
READ-ONLY
CAN'T CHANGE VALUE WHEN SET CAN BE INITIALIZED AT A LATER TIME LIKE IN A CONSTRUCTOR "READONLY" YOU CAN ONLY READ THE VALUE NOT WRITE IT
71
DO-WHILE LOOP
~EXECUTES ITS STATEMENT AT LEAST ONCE, WHILE THE CONDITION IS TRUE ITERATES THROUGH A BLOCK OF CODE & CONTINUES REPEATING THEM BASED ON A CONDITION UNTIL FALSE ~THE CONDITION IS NOTED ON THE BOTTOM AFTER THE WHILE PORTION OF THE STATEMENT
72
WHILE LOOP
EXECUTES BLOCK OF CODE BASED ON CONDITIONS WHILE TRUE UNTIL FALSE
73
Design Pattern
Design patterns provide typical solutions/ blueprints to solving commonly occurring problems in software design.
74
Creational Design Patterns
Creational design patterns are a category of design patterns that provide object creation mechanisms that increase flexibility and reusability of existing code.
75
The Singleton Design Pattern
This design pattern is a Creational design pattern. It lets the programmer ensure a class has only a one single instance while also providing a global access point to this instance.
76
When would the Singleton be used?
* Use the Singleton pattern when a class in your program should have just a single instance available to all clients; for example, a single database object shared by different parts of the program. * Use the Singleton pattern when you need stricter control over global variables.
77
Pros of using a Singleton Design Pattern
* You can be sure that a class has only a single instance. * You gain a global access point to that instance. * The singleton object is initialized only when it’s requested for the first time.
78
Cons of using a Singleton Design Pattern
* Violates the Single Responsibility Principle. The pattern solves two problems at the time. * The Singleton pattern can mask bad design, for instance, when the components of the program know too much about each other. * The pattern requires special treatment in a multithreaded environment so that multiple threads won’t create a singleton object several times. * It may be difficult to unit test the client code of the Singleton because many test frameworks rely on inheritance when producing mock objects. Since the constructor of the singleton class is private and overriding static methods is impossible in most languages, you will need to think of a creative way to mock the singleton. Or just don’t write the tests. Or don’t use the Singleton pattern.
79
The Factory Method Design Pattern
The Factory Method design pattern is a Creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.
80
Pros of using a Factory Method Design Principle
* You avoid tight coupling between the creator and the concrete products. * Single Responsibility Principle. You can move the product creation code into one place in the program, making the code easier to support. * Open/Closed Principle. You can introduce new types of products into the program without breaking existing client code.
81
Cons of using a Factory Method Design Principle
The code may become more complicated since you need to introduce a lot of new subclasses to implement the pattern. The best case scenario is when you’re introducing the pattern into an existing hierarchy of creator classes.
82
Structural Design Patterns
Structural design patterns explain how to assemble objects and classes into larger structures, while keeping these structures flexible and efficient. ex: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy, etc.
83
When would the Factory Method Design Pattern be used?
* Use the Factory Method when you don’t know beforehand the exact types and dependencies of the objects your code should work with. * Use the Factory Method when you want to provide users of your library or framework with a way to extend its internal components. * Use the Factory Method when you want to provide users of your library or framework with a way to extend its internal components.
84
The Facade Design Pattern
The Facade Design Pattern is a Structural design pattern that provides a simplified interface to a library, a framework, or any other complex set of classes.
85
When would the Facade Design Pattern be used?
* Use the Facade pattern when you need to have a limited but straightforward interface to a complex subsystem. * Use the Facade when you want to structure a subsystem into layers.
86
Pros of using a Facade Design Pattern
You can isolate your code from the complexity of a subsystem.
87
Cons of using a Facade Design Pattern
A Facade can become a god object coupled to all classes of an app.
88
Behavioral Design Patterns
Behavioral design patterns are concerned with algorithms and the assignment of responsibilities between objects.
89
The Mediator Design Pattern
Mediator is a behavioral design pattern that lets you reduce chaotic dependencies between objects. The pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object.
90
Pros of using a Mediator Design Pattern
- Single Responsibility Principle. You can extract the communications between various components into a single place, making it easier to comprehend and maintain. - Open/Closed Principle. You can introduce new mediators without having to change the actual components. - You can reduce coupling between various components of a program. - You can reuse individual components more easily.
91
Cons of using a Mediator Design Pattern
Over time a mediator can evolve into a God Object. **i.e. God object (sometimes also called an Omniscient or All-knowing object) is an object that references a large number of distinct types, has too many unrelated or uncategorized methods or some combination of both. The God object is an example of an anti-pattern and a code smell.
92
When would a Mediator Design Pattern be used?
* Use the Mediator pattern when it’s hard to change some of the classes because they are tightly coupled to a bunch of other classes. * Use the pattern when you can’t reuse a component in a different program because it’s too dependent on other components. * Use the Mediator when you find yourself creating tons of component subclasses just to reuse some basic behavior in various contexts.
93
The Strategy Design Pattern
The Strategy is a behavioral design pattern that lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.
94
Pros of using the Strategy Design Pattern
- You can swap algorithms used inside an object at runtime. - You can isolate the implementation details of an algorithm from the code that uses it. - You can replace inheritance with composition. - Open/Closed Principle. You can introduce new strategies without having to change the context.
95
Cons of using the Strategy Design Pattern
- If you only have a couple of algorithms and they rarely change, there’s no real reason to overcomplicate the program with new classes and interfaces that come along with the pattern. - Clients must be aware of the differences between strategies to be able to select a proper one. - A lot of modern programming languages have functional type support that lets you implement different versions of an algorithm inside a set of anonymous functions. Then you could use these functions exactly as you’d have used the strategy objects, but without bloating your code with extra classes and interfaces.
96
When would the Strategy Design Pattern be used?
* Use the Strategy pattern when you want to use different variants of an algorithm within an object and be able to switch from one algorithm to another during runtime. * Use the Strategy when you have a lot of similar classes that only differ in the way they execute some behavior. * Use the pattern to isolate the business logic of a class from the implementation details of algorithms that may not be as important in the context of that logic. * Use the pattern when your class has a massive conditional statement that switches between different variants of the same algorithm.
97
The Adapter Design Pattern
The Adapter is a structural design pattern that allows objects with incompatible interfaces to collaborate.
98
Pros of the Adapter Design Pattern
- Single Responsibility Principle. You can separate the interface or data conversion code from the primary business logic of the program. - Open/Closed Principle. You can introduce new types of adapters into the program without breaking the existing client code, as long as they work with the adapters through the client interface.
99
Cons of the Adapter Design Pattern
The overall complexity of the code increases because you need to introduce a set of new interfaces and classes. Sometimes it’s simpler just to change the service class so that it matches the rest of your code.
100
When would the Adapter Design Pattern be used?
* Use the Adapter class when you want to use some existing class, but its interface isn’t compatible with the rest of your code. * Use the pattern when you want to reuse several existing subclasses that lack some common functionality that can’t be added to the superclass.