C# Flashcards

1
Q

What is the CLR

A

Common Language Runtime

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

What does the C# compiler do?

A

It takes the C# code and transforms it into Microsoft Intermediate Language. If there are multiple files, it will produce a single executable or library. (And produce an executable?)

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

What is MISL/what does it do?

A

Microsoft Intermediate Language. MISL Defines instructions for the CLR

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

What does the CLR do?

A

Reads the MISL (Microsoft Intermediate Language) instructions and transforms intro instructions that the CPU on your machine will understand. (Native instructions)

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

What are native instructions?

A

Instructions that work on the real hardware where the program is running.

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

Is C# a case sensitive language?

A

Yes

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

What is the base index of arrays in C#

A

Zero

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

What are the two kinds of errors in C#

A

Compile Time, Run Time

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

In C#, what is a compile time error?

A

An error that occurs when the solution(project/code?) is being compiled.

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

In C#, what is a run time error?

A

A runtime error is a program error that occurs while the program is running.

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

In C#, what happens when a run time error is unhandled?

A

The CLR will shut down the application so it can not continue.

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

In a C# console app, where can I pass arguments for the debugger?

A

In the project properties, Debug tab, Command line arguments.

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

In Visual Studio, what is the autos debugging window for?

A

Show variables used around the current breakpoint.

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

What does it mean to say that C# is a typed language?

A

You have to have a type for every variable that you define.

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

In C# how do you name variables inside a method.

A

Starts with lower case letter. Each new word in the variable starts with an upper case letter.

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

In C# how do you name methods and classes?

A

Starts with an upper case letter.

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

What is in a class definition?

A

Starts with class keyword and name of the class. Everything inside is a class member.

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

What is a class State member

A

A class member that holds data

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

What is a class Behavior member

A

Members that do work. Methods is an example.

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

A field

A

Holds state for the class. It’s a class member. Field naming collection is lower case.

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

What does initializing an object do.

A

Reserves memory and give you a pointer to the memory?

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

Will C# accept an int as a float for a parameter typed as a float?

A

Yes

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

Will C# automatically accept a double as a float for a parameter typed as a float?

A

No.

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

How can you get C# to accept a double as a float?

A

Type an f at the end. Example 89.5f

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

What does the new keyword do here?: ClassName thing = new ClassName();

A

Instantiates an instance of the class. Creates an object. Instantiating a class invokes the constructor. The body of the constructor can contain initialization code.

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

Are private members visible in derived/child classes?

A

Only if the derived class is nested in the base class (a class defined within a class).

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

Where are protected members visible?

A

Only in derived classes.

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

Where are internal members visible?

A

Only in derived classes that are located in the same assembly as the base class.

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

Where are public members visible?

A

Public members are visible in all derived classes and can be used for any instantiation of a derived class.

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

Can derived classes override inherited members?

A

Yes, by providing an alternate implementation, but the base class member must be marked virtual. BY DEFAULT THEY ARE NOT MARKED AS VIRTUAL.

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

In C# what is a static class?

A

A static class cannot be instantiated. You can’t new it up. You access its methods by using the class name. EX. Console.WriteLine(). Console is a static class.

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

Name four features of a static class

A

Contains only static members, cannot be instantiated, is sealed, cannot contain instance constructors.

33
Q

What does FirstOrDefault() do

A

Without a predicate, it returns the first result in the IEnumerableSource, if any, or the default type of the enumerable. With a predicate, it returns the first matching element or the default of the source.

34
Q

What does SingleOrDefault() do

A

Returns the only element in the IEnumerable, default if the IEnumerable is empty and throws an exception if there is more than one element in the IEnumverable. OR returns the only element in the IEnumerable that matches the function. If there is more than one, it throws an error.

35
Q

What is the difference between first() and single()

A

First returns the first element of a sequence, or the first element of the sequence that matches the argument or throws an exception if there are no elements in the sequence. Single returns the only element that matches the arguments, or throws and error if no element matches the sequence or more than one element in the sequence matches the argument.

36
Q

What does .Reverse do in C#

A

Reverses the sequence of elements in an array of elements in a one-dimensional array.

37
Q

Will this compile in C#:var x = null;

A

No. You can not set an implicitly typed variable to null

38
Q

What is the difference between == and === in javascript

A

In the first operator, Javascript does the type conversion before checking equality. In the second, ‘===’ operator tests for strict equality i.e it will not do the type conversion hence if the two values are not of the same type, when compared, it will return false.

39
Q

What is hoisting in javascript

A

Hoisting is JavaScript’s default behavior of moving all declarations to the top of the current scope (to the top of the current script or the current function).

Sometimes, a variable can be used before it’s declared, the way the script is written.

40
Q

What is closure in Javascript

A

A closure is a function having access to the parent scope, even after the parent function has closed.

41
Q

What is .Net framework?

A

t is a platform for building various applications on windows. It has a list of inbuilt functionalities in the form of class, library, and APIs which are used to build, deploy and run web services and different applications. It supports different languages such as C#, VB .Net, Cobol, Perl, etc.

42
Q

What are the important components of .Net?

A

The components of .Net are Common language run-time, .Net Class library, Application domain, Common Type System, .Net framework, Profiling, etc. However, the two important components are Class library and Common Language Runtime.

43
Q

What is CTS?

A

CTS stands for Common Type System. It has a set of rules which state how a data type should be declared, defined and used in the program. It describes the data types that are to be used in the application.

We can design our own classes and values by following the rules that are present in the CTS. The rules are made so that the data type declared using a programming language is callable by an application that is developed using a different language.

44
Q

What is CLR?

A

Ans: CLR stands for Common Language Runtime. It is one of the most important components of .Net framework. It provides building blocks for many applications.

An application built using C# gets compiled by its own compiler and is converted into an Intermediate language. This is then targeted to CLR. CLR does various operations like memory management, Security checks, assemblies to be loaded and thread management. It provides a secure execution environment for applications.

45
Q

What is CLS?

A

CLS stands for Common Language Specification. With the rules mentioned under CLS, the developers are made to use the components that are inter-language compatible. They are reusable across all the .Net Compliant languages.

46
Q

What is JIT? in .NET?

A

JIT stands for Just In Time. JIT is a compiler that converts Intermediate Language to a Native code.

The code is converted into Native language during execution. Native code is nothing but hardware specifications that can be read by the CPU. The native code can be stored so that it is accessible for subsequent calls.

47
Q

What is meant by Managed and Unmanaged code?

A

The code that is managed by the CLR is called Managed code. This code runs inside the CLR. Hence, it is necessary to install the .Net framework in order to execute the managed code. CLR manages the memory through garbage collection and also uses the other features like CAS and CTS for efficient management of the code.

Unmanaged code is any code that does not depend on CLR for execution. It means it is developed by any other language independent of .Net framework. It uses its own runtime environment for compiling and execution.

Though it is not running inside the CLR, the unmanaged code will work properly if all the other parameters are correctly followed.

48
Q

How is a Managed code executed?

A

Ans: Following steps are followed while executing a Managed code:

Choosing a language compiler depending on the language in which the code is written.
Converting the above code into Intermediate Language by its own compiler.
The IL is then targeted to CLR which converts the code into native code with the help of JIT.
Execution of Native code.

49
Q

What is ASP.Net?

A

ASP .Net is a part of .Net technology and it comprises of CLR too. It is an open source server-side technology that enables the programmers to build powerful web services, websites and web applications.

ASP stands for Active Server Pages.

50
Q

Explain State management in ASP .Net.

A

State Management means maintaining the state of the object. The object here refers to a web page/control.

51
Q

What are the two kinds of state management in ASP.NET

A

There are two types of State management, Client Side, and Server side.

52
Q

What does state management consist of client side in ASP.NET?

A

Client Side – Storing the information in the Page or Client’s System. They are reusable, simple objects.

53
Q

What does state management consist of server side.

A

Server Side – Storing the information on the Server. It is easier to maintain the information on the Server rather than depending on the client for preserving the state.

54
Q

What is an Assembly? What are the different types of Assemblies?

A

Ans: An Assembly is a collection of logical units. Logical units refer to the types and resources which are required to build an application and deploy them using the .Net framework. The CLR uses this information for type implementations. Basically, Assembly is a collection of Exe and Dlls. It is portable and executable.

There are two types of Assemblies, Private and Shared.

Private Assembly, as the name itself suggests, it is accessible only to the application. It is installed in the installation directory of the Application.

A Shared assembly can be shared by multiple applications. It is installed in the GAC.

55
Q

In ASP.NET, what is the GAC?

A

The Global Assembly Cache (GAC) is a folder in Windows directory to store the .NET assemblies that are specifically designated to be shared by all applications executed on a system. Assemblies can be shared among multiple applications on the machine by registering them in global Assembly cache(GAC). A Developer tool called Gacutil.exe is used to add any file to GAC.

56
Q

Explain the different parts of an Assembly.

A

Ans: The different parts of an Assembly are:

Manifest – It contains the information about the version of an assembly. It is also called as assembly metadata.
Type Metadata – Binary information of the program.
MSIL – Microsoft Intermediate Language code.
Resources – List of related files.

57
Q

What is an EXE and a DLL?

A

Exe and DLLs are Assembly executable modules.

Exe is an executable file. This runs the application for which it is designed. An Exe is generated when we build an application. Hence the assemblies are loaded directly when we run an Exe. However, an Exe cannot be shared with the other applications.

DLL stands for Dynamic Link Library. It is a library that consists of code which needs be hidden. The code is encapsulated inside this library. An Application can consist of many DLLs. These can be shared with the other applications as well.

Other applications which need to share this DLL need not worry about the code intricacies as long as it is able to call the function on this DLL.

58
Q

What is Caching?

A

Caching means storing data temporarily in the memory so that the application can access the data from the cache instead of looking for its original location. This increases the performance of the application and its speed. System.Runtime.Caching namespace is used for Caching information in .Net.

Given below are the 3 different types of Caching:

Page Caching
Data Caching
Fragment Caching

59
Q

What is MVC?

A

MVC stands for Model View Controller. It is an architectural model for building the .Net applications.

Models – Model objects store and retrieve data from the database for an application. They are usually the logical parts of an application that is implemented by the application’s data domain.

View – These are the components that display the view of the application in the form of UI. The view gets the information from the model objects for their display. They have components like buttons, drop boxes, combo box, etc.

Controllers – They handle the User Interactions. They are responsible for responding to the user inputs, work with the model objects, and pick a view to be rendered to the user.

60
Q

What is the difference between Function and Stored procedure?

A

Stored Procedure:

A Stored procedure is always used to perform a specific task.
It can return zero, one or more value.
It can have both Input and Output Parameters.
Exception handling can be done using a try-catch block.
A function can be called from a Procedure.
Functions:

Functions must return a single value.
It can only have the input parameter.
Exception handling cannot be done using a try-catch block.
A Stored procedure cannot be called from a function.

61
Q

Explain CAS (Code Access Security).

A

.Net provides a security model that prevents unauthorized access to resources. CAS is a part of that security model. CAS is present in the CLR. It enables the users to set permissions at a granular level for the code.

CLR then executes the code depending on the available permissions. CAS can be applied only to the managed code. Unmanaged code runs without CAS. If CAS is used on assemblies, then the assembly is treated as partially trusted. Such assemblies must undergo checks every time when it tries to access a resource.

62
Q

What are the different components of CAS?

A

Code group, Permissions, and Evidence.

63
Q

In .NET CAS, what is evidence?

A

Evidence– To decide what permissions to give, the CAS and CLR depend on the specified evidence by the assembly. The examination of the assembly provides details about the different pieces of evidence. Some common evidence include Zone, URL, Site, Hash Value, Publisher and Application directory.

64
Q

In .NET CAS, what is Code Group?

A

Depending on the evidence, codes are put into different groups. Each group has specific conditions attached to it. Any assembly that matches those condition is put into that group.

65
Q

In .NET CAS, what is Permissions?

A

Each code group can perform only specific actions. They are called Permissions. When CLR loads an assembly, it matches them to one of the code groups and identifies what actions those assemblies can do. Some of the Permissions include Full Trust, Everything, Nothing, Execution, Skip Verification, and the Internet.

66
Q

In .NET, what is meant by Globalization and Localization?

A

Internationalization is the process of designing applications that support multiple languages. This is divided into Localization and Globalization.

Globalization is nothing but developing applications to support different languages. Existing applications can also be converted to support multiple cultures.

Whereas Localization means changing the already globalized app to cater to a specific culture or language Microsoft.Extensions.Localization is used for localizing the app content. Some of the other keywords that are used for Localization are IHtmlLocalizer, IStringLocalizer, IViewLocalizer and so on

67
Q

What is a Garbage Collector?

A

Garbage collection is a feature of .Net to free the unused code objects in the memory.

The memory heap is divided into three generations. Generation 0, Generation 1 and Generation 2.

Generation 0 – This is used to store short-lived objects. Garbage Collection happens frequently in this Generation.

Generation 1 – This is for medium-lived objects. Usually, the objects that get moved from generation 0 are stored in this.

Generation 2 – This is for long-lived objects.

Collecting a Generation refers to collecting the objects in that generation and all its younger generations. Garbage collection of Generation 2 means full garbage collection, it collects all the objects in Generation 2 as well as Generation 1 and Generation 0.

During the Garbage collection process, as the first phase, list of live objects are identified. In the second phase, references are updated for those objects which will be compacted. And in the last phase, the space occupied by dead objects are reclaimed. The remaining objects are moved to an older segment.

68
Q

What is the operator precedence in C#?

A

In an expression with multiple operators, the operators with higher precedence are evaluated before the operators with lower precedence.
M / D / A / S

69
Q

How do you override operator precedence in C#?

A

Parenthesis

70
Q

What does these operators do? ?. ?[]

A

These are member access operators. As in A?.B?.Do(C);
A?.B?[C];
If A is not null, then it will move on to B. If B is not null, then it will execute Do(C). If any element in the chain is null, then null is what is returned.
As demonstrated, these operators can be chained.

71
Q

What does the operator in x++ do?

A

x++ is the incremental operator. It adds 1 to some value. However the value of x++ is x BEFORE the operation takes place.

The postfix increment operator
int i = 3;
Console.WriteLine(i);   // output: 3
Console.WriteLine(i++); // output: 3
Console.WriteLine(i);   // output: 4
72
Q

What does the operator in ++x do?

A
The prefix increment operator
double a = 1.5;
Console.WriteLine(a);   // output: 1.5
Console.WriteLine(++a); // output: 2.5
Console.WriteLine(a);   // output: 2.5
73
Q

How does the decrement operator (–) work?

A

It decreases some value by 1.

74
Q

What are the SOLID coding principles?

A
Single responsibility principle
Open/Closed principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
75
Q

What is the Single responsibility principle

A

Single Responsibility Principle or SRP states that every class should have a single responsibility. There should never be more than one reason for a class to change.

76
Q

What is the Open/Closed Principle

A

Open/Closed Principle or OCP states that software entities should be open for extension, but closed for modification.

77
Q

What is the Liskov Substitution Principle

A

Liskov Substitution Principle or LSP states that objects in a program should be replaceable with instances of their subtypes without altering the correctness of the program.

78
Q

What is the Interface Segregation Principle

A

Interface Segregation Principle or ISP states that many client-specific interfaces are better than one general-purpose interface. In other words, you should not have to implement methods that you don’t use. Enforcing ISP gives you low coupling, and high cohesion.

79
Q

What is the Dependency Inversion Principle

A

Dependency Inversion Principle¶
Dependency Inversion Principle or DIP has two key points:

Abstractions should not depend upon details;
Details should depend upon abstractions.
This principle could be rephrased as use the same level of abstraction at a given level. Interfaces should depend on other interfaces. Don’t add concrete classes to method signatures of an interface. However, use interfaces in your class methods.