T Interv.NEiew Flashcards
What is composition?
The ability to build functions by using other functions is called composition
what is scaffolding?
Code that is used to assist with development and debugging. Unit test code is an example of scaffolding.
What is the difference between a block and a body?
A block is group of consecutive statements with the same indentation.
A body is a kind of block that is found after a method’s header.
What is an example of definite iteration?
a for loop
What is an example of indefinite iteration?
a while loop
What are collection classes used for?
maintaining lists of objects
What is IList used for?
IList Provides a list of items for a collection along with the capabilities for accessing these items, and some other basic capabilities related to lists of items
What is IDictionary used for?
IDictionary — Similar to IList, but provides a list of items accessible via a key value, rather than an index
Can an interface have a body?
No
An abstract class allows you to create functionality that subclasses _______
inherit (or override??)
Can you apply access modifiers to abstract classes or interfaces, which one?
Only abstract classes
Do you use abstract classes or interfaces to provide multiple inheritance in C#?
Interfaces only
What access modifier must interface members be implicitly implemented with?
public
What is the syntax for explicit implementation?
.
IFile.ReadFile()
Describe an interface
An interface is an empty shell. Only signatures, no bodies. An interface can’t do anything. It’s just a pattern.
Can you define behavior in an interface?
No. Interfaces can only have signatures.
Which constructor would be called first? A base class, or a sub class?
sub class
What is the essential difference between interfaces and abstract classes?
Where you want to define behavior
Is an abstract class an example of a “is-a” relationship, or a “has-a” relationship?
is-a
a Tank is a Vehicle
Are abstract classes or interfaces “implemented”, which one?
interfaces
Are interfaces or abstract methods more expensive to use?
abstract classes
If the proposed base class doesn’t provide default implementations for your methods, is this a reason to choose inheritance or an interface?
interface
If it makes sense to call a method even when no object has been constructed yet, how should that method be defined?
static
Can you override a static method?
no
Does a static method produce a state?
no
If there is some code that can easily be shared by all the instance methods, what should you do with that code?
Extract that code into a static method
Can a static method be garbage collected?
No
Is using static methods is always thread safe?
No
If you have something consuming your classes, and you want to ensure that all of the classes implement the same methods and properties, but not necessarily the same functionality, what would you use?
Interfaces
If you have common functionality you want available in all child classes, where each child class can extend or override the parent class code, what should you use?
you should use inheritance (Abstract classes)
A METHOD without a body is known as?
An abstract method
Can you create an object from an abstract class?
No
What is abstraction?
Data abstraction is the process of hiding certain details and showing only essential information to the user
A constructor name must match _________, and it cannot have a _________
The class name, a return type
Describe Process vs Thread?
Process is an independent execution unit with its own state and memory; Architectural construct.
Threads exist inside of a Process and share state and memory; coding construct
What is overloading?
Adding to the functionality of a method, while keeping the same name. It’s a compile time event.
int add(int a, int b) return a+b; int add(int a, int b, int c) return a+b+c;
(note, both of these are usable, the second one doesn’t overwrite the first one. So overloading is a way of adding to the capabilities of a method, while overriding is re-writing methods that already exist)
What is the default access modifier for a namespace?
internal
What is the difference between IEnumerable and ICollection?
When we define a property as IEnumerable, we can only iterate through each item. But when we define a property as ICollection, we can add, edit, update and delete an item.
What is overriding?
You override a virtual method in a sub class. Overriding concerns defining a different implementation of the same method in inherited classes. It is a runtime event
what is hiding?
public class Base_Parent { public void show() Console.WriteLine("This is my parent class."); }
public class Derived _Parent : Base_Parent { public new void show() Console.WriteLine("This is my child class."); }
Are abstract classes or interfaces “inherited”?
abstract classes
An event is nothing but a?
encapsulated delegate
How would you declare an event for the following delegate?
public delegate void ClickHandler();
public event ClickHandler OnClick;
Which of the following is the built-in delegate function for handling events in .NET?
public delegate void EventHandler(object sender, EventArgs e);
online c# tests
https://www.tutorialsteacher.com/question-answer/csharp/delegates-events/2
Which can only be initialized at the class-level, const or readonly?
readonly
What are fields?
variables inside a class
Which is a compile time constant, const or readonly?
const
Which can be changed, const or readonly?
readonly
What kind of search starts at a given node and explores as far as possible along each branch before back tracking?
Depth-first search
What kind of search starts at a given node and explores all neighboring nodes before moving deeper?
Breadth-first search
What does the public access modifier do?
The type or member can be accessed by any other code in the same assembly or another assembly that references it
In BFS, we need to maintain a separate data structure for tracking the nodes yet to be visited.
In DFS doesn’t need any additional data structure to store the nodes. The recursive implementation of DFS uses the call stack
How does garbage collection work in C#?
Automatic by default, though you can do it manually using pointers
What triggers garbage collection in C#?
An allocation is made any time you declare an object with a “new” keyword.
When there is not enough memory to allocate an object, the garbage collector must collect and dispose of garbage memory.
Why would you ever use SQL over LINQ?
SQL is still faster. And you still sometimes need SQL for hand-tweaked queries - especially with optimization or locking hints. Most providers don’t support the use of LINQ for predicated updates, and of course you still need SQL for triggers.
What do LINQ to SQL queries compile into?
SQL queries
Why use LINQ over SQL?
Shorter, more readable code No magic strings Intellisense Compile check when database changes Unit of work pattern (context) Lazy loading
What is an enum?
An enum is a special “class” that represents a group of constants
What are assemblies in C#?
compiled .exe or .dll files
What does the private access modifier do?
The type or member can be accessed only by code in the same class or struct.
What is encapsulation?
The meaning of Encapsulation, is to make sure that “sensitive” data is hidden from users. To achieve this, you must:
Declare fields/variables as private
Provide public get and set methods, through properties, to access and update the value of a private field
When to use DFS and BFS?
If we know the solution lies somewhere deep in a tree or far from the source vertex in the graph, use DFS.
If we know the solution is not that far from the source vertex, use BFS.
If our tree is broad, use DFS as BFS will take too much memory. Similarly, if our tree is very deep, choose BFS over DFS.
What does the protected access modifier do?
The type or member can be accessed only by code in the same class, or in a class that is derived from that class.
Entity Framework questions
x
MVC vs MVVM
x
How do you prevent deadlocks when two threads need the same n resources?
A deadlock occurs when each thread (minimum of two) tries to acquire a lock on a resource already locked by another. Thread 1 locked on Resources 1 tries to acquire a lock on Resource 2. At the same time, Thread 2 has a lock on Resource 2 and it tries to acquire a lock on Resource 1. Two threads never give up their locks, hence the deadlock occurs.
The simplest way to avoid deadlock is to use a timeout value. The Monitor class (system.Threading.Monitor) can set a timeout during acquiring a lock.
What are your options if a resource must be locked in one section and released in another?
x
What does ThreadStatic mean?
The [ThreadStatic] creates isolated versions of the same variable in each thread. Fields marked with [ThreadStatic] are created on Thread Local Storage so every thread has it own copy of the field i.e the scope of the fields are local to the thread.
What is reflection? (Why would you use it and also why wouldn’t you use it?)
x
Have you heard of SOLID? (can you show examples in your code, does the code you submitted violate any of the SOLID principles?)
x
What are the important qualities of a Unit Test?
x
How would you mock or stub a sealed class that does not implement any interfaces? A static class?
x
What does an API controller do?
x
Explain C#’s reference and value types, and explain the differences.
x
Explain what @Html. does and what it is.
x
MVC Explain all of the steps that go into a user getting to a certain page. Try to list the events that occur and what order they happen in.
https://docs.microsoft.com/en-us/previous-versions/aspnet/ms178472(v=vs.100)
viewstate/session state, what are the different http methods and what do we use them for, difference between full postback and Ajax requests etc
x
What does the internal access modifier do?
The type or member can be accessed by any code in the same assembly, but not from another assembly.
What is a value type?
Usually a simpler type of data, where the data and the pointer is kept on the stack
int
float
bool
char
What is a reference type?
Usually more complex types of data, where the data is kept on the heap.
class delegate string
What is a delegate?
A delegate in .NET is a way of passing behavior as a parameter. Similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object
Often used in async methods
What is a namespace?
A group of classes, structures, interfaces, enumerations, and delegates—organized in a logical hierarchy