Omni Flashcards
What is a Delegate?
A way of passing behavior as a parameter
What are Default Constructors?
Methods that don’t return anything or take any parameters
What are Static Members shared between?
Static Members are shared between Instances of a Class
What is a Model?
A Model is an abstraction of something
What does the “new” keyword do?
It allocates memory at run time
What is Inheritance?
If a Class B inherited from Class A then it contains all characteristics (information structure and behavior) of Class A
What is a naive way of writing code line by line?
Procedural Programming
What is Error Handling?
Error Handling is the term for all techniques involving Finding and Correcting Errors
What are the 3 categories that Operators can be divided into?
Unary, Binary, and Ternary
What is the term for a variable in a Struct?
a Data Member
In C#, what is a Field?
A Field is a Variable of any type that is declared directly in a Class or Struct. Fields are Members of their containing type.
What is the difference between a Function and a Method?
A Method is a special type of function with an Implicit Argument Passed (an instance of the class that the method is defined on). This is important, as a Function, in strict terms, should not use or modify anything not in its argument list
Where can you access Private Members from?
Only from Inside the Class
In a Switch statement, it is legal to execute more than one case?
Yes
Can you instantiate an Abstract class?
No
What is the “Diamond Problem”?
In multiple Inheritance, if intermediate classes inherit from same base class then the 3rd level of child class will have the same behavior from two classes
What is Association in OOP?
Object interaction with each other is called Association
What are the 2 main types of Association?
- Class association (inheritance)
- Object association (simple association, composition, aggregation)
What is the difference between “.” and “->” ?
The dot operator “.” accesses type through name
The arrow key operator “->” accesses type through a pointer
What is the purpose of the scope resolution operator?
If you declare a Function inside a Class and define it Outside the Class then you need to use the Scope Resolution Operator “::”
What is a Constructor?
A Constructor is used to Initialize the Objects of Class. The Constructor is automatically called when the Object is Created. It does not have return type.
What is a Destructor?
A Destructor is used to free the memory that is allocated through dynamic memory allocation. It destroys an object when it goes out of scope. Destructors use “~” as prefix
Can Destructors be overloaded?
Yes
How is a Destructor called?
In reverse order
What are Accessors?
Accessors are used to access data members that are defined as private.
Name four Integer Types
Byte, Short, Int, Long. All are also available in Signed and Unsigned versions.
Can Interfaces exist on their own?
No
What is an Interface?
A collection of Private instance Methods and Properties that are grouped together
What does the term Inheritance mean in OOP?
Inheritance is when one class inherits all the Members of another class
What is a Struct?
Data structures that are composed of several pieces of data, possibly of different types
In C#, all Classes are derived from what?
The Base Class Parent at the Root of the Class, and ultimately System
What are Non-default Constructors?
Non-default Constructors are Constructors that include Default Parameters
What does Polymorphism allow?
All Objects Instantiated from a Derived Class can be Treated as if they were Instances of a Parent Class
Are Protected Members accessible anywhere?
No, only from code that is either part of the Class or a Derived Class
Are Public Members accessible anywhere?
Yes
Within a Class definition, do all Members have the same accessibility levels?
No
Which Keyword makes Members Accessible only from code within the assembly (project) where they are defined?
Internal
What are the 4 Class Definition Modifiers for accessibility?
Public, Private, Internal, and Protected
Why would you use the Global keyword?
If you have a conflict between a Class Name and a Namespace, for example, you can use the Global keyword to access the Namespace
If Override is used, can sealed also be used to specify that no further modifications can be made to this method in derived classes?
Yes
Can Accessors be used to control the access level of the Property?
Yes
Accessors are defined using what keywords?
Get and Set
What does the Override modifier do?
The Override Modifier is required to extend or modify the Abstract or Virtual implementation of an Inherited Method, Property, Indexer, or Event
What is Inheritance in classes?
If a Class B inherited from Class A then it contains all the characteristics (information structure and behavior) of Class A
What is Generalization?
Generalization means multiple Classes can Inherit the same Attributes from the parent Class
A Generalization of Cats and Dogs could be?
A. Tabby
B. Mammals
C. Yellow Lab
D. Fur
Mammals
A Specialization of Fish could be?
A. Under Water
B. Animals
C. Whales
D. Tuna
Tuna
What is Containment?
When one class contains another
What is the base class in C#?
System
Abstract classes can possess what kind of members?
Abstract Members and Non-Abstract Members.
Can Abstract Classes contain Members that can be Inherited by a Derived Class?
Yes
Can Interfaces contain Members that can be Inherited by a Derived Class?
No
When you assign an object to a variable, are you actually assigning that variable with a pointer to the object to which it refers?
Yes
What does passing a parameter by reference mean?
The referenced variable will be used each time a function is run rather than using a constant number
A Full Copy is referred to as what?
A Deep Copy
What is the term for the .Net method of freeing up unused memory?
Garbage collection
Properties contain a Type Name, a Property Name, and one or both kind of Blocks?
Get and Set
Do you have to use an Accessor to make a Property useful?
Yes
Do Properties use the same keywords as Fields and Methods?
Yes
What does the keyword “value” refer to?
Equates to a value of the same type as the property
Is Refactoring usually done by hand, or with a tool?
A tool
What is Refactoring?
Code Refactoring is the process of Restructuring existing computer code, Without changing its external Behavior
What is an Object?
A collection of Variables and possibly Functions
Is the main limitation of Automatic Properties that they must include both a Get and Set Accessor?
Yes
When you inherit a Non-Abstract Member from a Base Class, do you also inherit an Implementation?
Yes
Why are Properties the preferred way to access the State of an Object?
They shield external code from the implementation of data storage within the object
With an Automatic Property, you declare what?
A Property with a simplified syntax
When a Base Implementation is hidden, how can you still access it?
By using the Base keyword
Can you define Types such as Classes in Namespaces?
Yes
Can you define Types inside other Classes?
Yes
Is the most useful function of the Base keyword the capability to pass a reference to the current Object instance to a method?
No
Like Base, this refers to an Object instance, although it is a Future Object instance
No
What does the “this” keyword refer to?
An Object Instance
How do Implicit and Explicit Conversions differ?
Implicit: conversion is possible in all circumstances, and the compiler can do it.
Explicit: conversion is possible only in certain circumstances
What is the keyword “this” used for in C#?
To pass a reference of the current object instance to a method
What type of language is C#?
a Strongly Typed, Block-Structured language
Are Interface Members have implementations (bodies)?
No
Can Interfaces can contain code bodies?
No
Why would you want to use the “new” keyword in defining Interface Members?
If you want to hide Members inherited from base Interfaces
A Class that implements an Interface Must Contain implementations for All Members of that Interface
Yes
Do Interface values specify how the property data should be stored?
No
It is possible to Implement Interface Members using the keyword Virtual or Abstract?
Yes
Is it true Interface Members cannot be Implemented Explicitly by a Class?
No
It is possible to add a Get block to a property in a Class in which the Interface defining that property only contains a Set block, and vice versa?
Yes
How do you declare an array?
”[ ]”
What is the code that allows fields to expand and contract?
region and #endregion
In what two forms can you copy the Constructor?
Deep Copy
Shallow Copy
What is the difference between a Class variable and an Instance variable?
Class variables only have one copy that is shared by all the different objects of a class, whereas every object has it’s own personal copy of an instance variable. So, instance variables across different objects can have different values whereas class variables across different objects can have only one value.
Can Static Methods be instantiated?
No
What is a Deep Copy?
If an object has pointers to dynamically allocated memory, and the dynamically allocated memory needs to be copied when the original object is copied, then a Deep Copy is required.
What is a Shallow Copy?
A Shallow Copy of an object copies all of the member field values.
It is possible to Implement Interface members using the keyword Static or Const?
No
Can Overloading effect Associativity?
No
Are Unary operators and Assignment operators right or left associative?
Right
What is an Explicit Conversion or Cast?
Casting is required when information might be lost in a conversion from one type to another, or when the conversion might not succeed for other reasons. A typical example would be numeric conversion to a type that has less precision or a smaller range.
float x = 3.25;
int y = (int)x; // y == 3
How would you Cast “x” as an int?
(int)x
What is the goal of Object Oriented Programming?
Modularity and Extensibility
Write code using a Ternary Operator that sets x equal to y if x is greater than y, or sets x equal to b if x is less than or equal to y
x > y ? x = y : x = b
In .NET, do you immediately create operating system-specific native code, or do you compile into Common Intermediate Language code?
Common Intermediate Language code
What are Collection classes used for in general?
Maintaining lists of objects
What keyword can you use to declare a variable without specifying a data type explicitly?
var
Are strings Immutable in C#?
Yes
Can you apply Access Modifiers to Interface Members?
No
What would the code look like where a FileInfo class implements an IFile interface?
class FileInfo : IFile
What keyword would you use to split a Method?
partial
How might a partial class definition be used?
Put the fields, properties, and constructor in one file, and the method in another
Can a Method be split between files?
Yes. Using partial
Can Partial Methods be static?
Yes
Must a Class that implements an Interface implement all of the Members defined by that interface?
Yes
A Class that Implements an Interface must implement the members with what modifier?
Private
What are some restrictions Partial methods have?
No return value, No out parameters
Properties and Methods can be defined as ______ or ______ in Base Classes to define Inheritance
Abstract or Virtual
What do Collections enable you to maintain?
Groups of Objects
What is the Ternary Operator syntax?
condition ? do if true : do if false
How would you declare a “x” as a nullable int?
int? x
Why not to use “var” everywhere?
“var” isn’t a performance hit, but it can make code harder to understand. “var” obscures the actual variable type, so if the initializer doesn’t return a clearly defined type then you may not be able to tell the what type of data you’re dealing with
How would you declare a function called “MyFunc” with a nullable boolean parameter named “flag”?
MyFunc (bool? flag) { }
How would you declare a function called “EvalPi” with a parameter of type double called “input” that has a default value of “3.14”?
EvalPi (double input = 3.14) { }
Which type of Case should you use to name a Method or Function in C#?
A. Camel Case B. Snake Case C. Pascal Case D. _lowerCamelCase E. Kebab Case F. lowerCamelCase
C. Pascal Case
Which type of Case should you use to name a Namespace in C#?
A. Camel Case
B. Snake Case
C. Pascal Case
D. Kebab Case
C. Pascal Case
What is the best practice for naming Interfaces in C#?
Start the name with an upper case “I”, followed by Pascal Case. For example, “IMyInterface”
Which type of Case should you use to name a Private Field in C#?
_lowerCamelCase
Which type of Case should you use to name a Local Variable in C#?
lowerCamelCase
Which type of Case should you use to name a Parameter in C#?
lowerCamelCase
Which Member has an Accessibility, Return Type, and Parameters?
Fields
Declare a pointer variable x, which can hold the address of an int type
int *x
Assign the memory address of x to a pointer variable
int ptr = & x;
Console.WriteLine((int)ptr) // Displays the memory address
Console.WriteLine(ptr) // Displays the value at the memory address.
What is the C# name for a Destructor?
A Finalizer
Can Finalizers be defined in Structs?
No
How many Finalizers can a class have?
1
Can Finalizers be inherited?
No
Can Finalizers be overloaded?
No
Can a Finalizer be called?
No
Does a Finalizer take modifiers or have parameters?
No
How would you write Auto Implemented Properties for a public property called “Name” of type String?
public string Name { get; set; }
Do you have to instantiate an Object to make use of a Static Class?
No. In fact, you can’t
What kind of linkage does the keyword Static create?
Internal
If the keyword Static is used outside of a class, what does that do?
That function’s scope is limited to the file where it is declared. It can’t be exported, or called elsewhere
How would you create a list of type string?
List
What does the Abstract Keyword enable you to do?
The abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class
Can an Abstract class be instantiated?
No
How many Base Classes can a Class have?
1
What is Lazy Initialization of an object?
Assume you have property that contains a large array of objects that, to be initialized, requires a database connection. If the user never asks to display the Orders or use the data in a computation, then there is no reason to use system memory or computing cycles to create it.
What is a wrapper class that provides lazy initialization for any class library or user-defined type?
Lazy
What is Caching?
If you have an expensive object, you save it to process memory and reuse it, instead of running the code to produce it over and over
What types of relationships are in OOP?
Is-a and Has-a
Another name for a Parent Class could be a?
Super Class
Another name for a Child Class could be a?
Sub Class
What does the keyword “virtual” allow?
For a method to be overrideable when it’s inherited
What Keyword is used to make a method behave differently in a sub class than in its super class?
override
Can an Abstract Method declare a body (or block) ?
No
Can a Virtual Method declare a body (or block) ?
Yes
What is another name for a non-abstract class?
A concrete class
What type of class MUST be overridden, Abstract or Virtual?
Abstract
What is Polymorphism?
How we change the behavior of the base class when we create a sub class
What is a Class Hierarchy?
The design, or topology, of how classes are inherited from other classes
What are the three pillars of OOP?
Polymorphism, Encapsulation and Inheritance
What Keyword can we use to re-use the name of a method in the base class in the sub class for a different purpose?
new
Bonus: This is called Hiding
What is Client Code?
Some methods and properties are meant to be called or accessed from code outside a class or struct
Classes may be declared as _______, which means that one or more of their methods have no implementation
abstract
True or False, to inherit from an interface means that the type implements all the methods defined in the interface
True
What does the Keyword Static do?
One copy of the class is loaded into memory when the program loads, and its members are accessed through the class name
Can you instantiate and initialize class or struct objects, and collections of objects, without explicitly calling their constructor?
Yes
What are Anonymous Types?
Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and is not available at the source code level.
You create anonymous types by using the new operator together with an object initializer.
“var” is almost always used
What is an Extension Method?
You can “extend” a class without creating a derived class by creating a separate type whose methods can be called as if they belonged to the original type
What are Generics?
Generics 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.
For example, by using a generic type parameter T, you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations
What does passing a parameter by reference mean?
Passing a parameter by reference means the referenced variable will be used each time a function is run rather than making a copy of the variable, such as with a value type
What are some differences between Arrays and Collections?
Unlike Arrays, Collections can Control Access to the objects they contain, Search and Sort, and more
What does the Sealed Keyword do?
The Sealed Keyword enables you to Prevent the Inheritance of a Class Or certain class Members that were previously Marked Virtual
Where is a Class stored in memory?
On the Heap
Where are Structs stored?
On the Stack
Typically, which is smaller, the Stack or the Heap?
The Stack
Write a foreach loop that uses regex to look for the word “you” in a string named input
foreach(Match m in Regex.Matches(input, “you”)) {}
What is IL?
Intermediate Language code. It is a partially compiled code
What is JIT?
Just In Time compilation. In C#, JIT compiles IL into machine language
Is it possible to view IL code?
Yes, by using a Disassembler, such as DASM
Why do we need to compile into IL first? Why not directly to machine code?
The developer environment and the runtime environment can be very different. You may develop on Windows 10, but the code may be run on Mac, for example. Intermediate Language can be compiled into almost any platform
What language must you code a .NET project in?
Trick question. You can code a .NET project in several languages.
What is the importance of CLR?
Common Language Runtime invokes IL to compile into Native code. Also, Garbage collection is done in the CLR
What is unmanaged code?
Code that is imported, and used as is, that is not under the control of the CLR. Unmanaged code has its own environment and runtimes.
Importing .dll’s that were written in C++ is one example
Does garbage collection run on unmanaged resources?
No
What is CTS?
Common Types System. It ensures that data types created in different languages get compiled to a common data type.
What is CLS?
Common Language Specification. A set of guidelines that helps ensure any program written in a .NET language can be consumed by .NET CLR.
Rules for different data types, use of pointers, functional programming, etc
When an object is instantiated, is it’s pointer stored on the Heap or the Stack?
The Stack
Where is the data, or values, of an object stored? Heap or Stack?
Heap
How are Value Types stored as far as the Stack and the Heap are concerned?
With Value Types, the value and the pointer are both stored on the Stack.
int, bool, etc
How are Reference Types stored as far as the Stack and the Heap are concerned?
With Reference Types, the the pointer is stored on the Stack, however the value(s) are stored on the Heap.
string, objects, etc
What is Boxing?
Moving a Value Type to a Reference Type
What is Unboxing?
Moving a Reference Type to a Value Type
What is the problem with Boxing and Unboxing?
Performance. It’s expensive to move data around, especially from Stack to Heap.
What is an Array?
An Array is a data structure of a series of data of the same type. It is a specific contiguous location in memory and it has a fixed length. (technically yes, an array can be resized, but this is expensive)
What is an ArrayList?
Flexible length, can mix and match different types
What two data types do you get the best of with Generics?
Arrays and Lists
What is Threading in a simple sense?
When you want to run processes in parallel, or more than one process at a time
How would you create a variable named v with an anonymous type of Amount = 108 and Message = “Hello”
var v = new { Amount = 108, Message = “Hello” };
What is the Big O notation for Binary search?
O(log n)
What is the Big O notation for Simple search?
O(n)
What is the Big O notation for Quicksort?
O(n * log n)
What is the Big O notation for Selection Sort?
O(n^2)
What is the Big O notation for Traveling Salesperson?
O(n!)
What’s 1 example of a possible problem with Hash Tables?
Collisions
What is a common way of dealing with Collisions in Has Tables?
Chaining