General Flashcards
What is C#
C# is an object-oriented programming language that was created by Microsoft.
It runs on the .NET framework.
Similar to C++ and Java.
How is C# different from C
C supports procedural programming; C# is object-oriented.
C supports pointers; C# pointers are used only in unsafe mode.
No garbage collection in C; in C# garbage collection is managed by the Common Language Runtime (CLR).
C can be executed cross-platform; C# requires the .NET framework.
C achieves low level abstraction; C# offers a high degree of abstraction.
What is Common Language Runtime (CLR)
CLR is the basic and Virtual Machine component of the .NET framework. It is the runtime environment in the .NET Framework.
It is responsible for managing execution of .NET programs regardless of the language.
What are Indexers in C# .NET
Indexers are known as smart arrays in C#. They allow instances of a class to be indexed in the same way as an array.
What is the JIT compiler process
Just-in-Time compiler is a part of the Common Language Runtime in .NET. It is responsible for managing the execution of .NET programs.
A language specific compiler converts the source code to the intermediate language.
This intermediate language is then converted into the machine code by the Just-In-Time (JIT) compiler.
This machine code is specific to the computer environment that the JIT compiler runs on.
What is garbage collection in C#
When a class object is created at runtime, certain memory space is allocated to it in the heap memory. However, after all the actions related to the object are completed in the program, the memory space allocated to it is a waste as it cannot be used. In this case, garbage collection is very useful as it automatically releases the memory space after it is no longer required.
What are the conditions under which Garbage Collection runs
If the system has low physical memory, then garbage collection is necessary.
If the memory allocated to various objects in the heap memory exceeds a pre-set threshold, then garbage collection occurs.
If the GC.Collect method is called, then garbage collection occurs. However, this method is only called under unusual situations as normally garbage collector runs automatically.
What are the types of classes in C#
Abstract class Partial class Sealed class Static class
What is the difference between an abstract class and an interface
AC contains both declaration and definition parts; Int contains only a declaration part.
Cannot achieve multiple inheritance with AC; May achieve multiple inheritance with Int.
AC contains a constructor; Int does not.
AC can contain static members; Int cannot.
AC can contain different modifiers such as public, private, etc; Int must have all members as public.
AC performance is faster than Int.
AC is used to implement core identity of class; Int used to implement peripheral abilities of a class.
What are extension methods in C#
They allow you to add new methods in the existing class or in the structure without modifying the source code of the original type, and you do not require any kind of special permission from the original type and there is no need to re-compile the original type.
Does C# allow for multiple inheritance?
No, C# does not support multiple class inheritance
What is Managed Code?
Managed Code is aimed to get the services of the managed runtime environment like CLR.
What is Unmanaged Code
Code that is directly executed by the operating system. It is always aimed at the processor architecture and depends on the computer architecture.
What is the difference between a struct and a class in C#
A class is a user-defined blueprint or prototype from which objects are created. Basically, a class combines the fields and methods(member function which defines actions) into a single unit.
A structure is a collection of variables of different data types under a single unit. It is almost similar to a class because both are user-defined data types and both hold a bunch of different data types.
What is an enum in C#
Enumeration (or enum) is a value data type in C#. It is mainly used to assign the names or string values to integral constants, which make a program easy to read and maintain.
What is the ref keyword
The ref keyword indicates that a value is passed by reference. It is used in four different contexts:
In a method signature and in a method call, to pass an argument to a method by reference.
In a method signature, to return a value to the caller by reference.
In a member body, to indicate that a reference return value is stored locally as a reference that the caller intends to modify. Or to indicate that a local variable accesses another value by reference.
In a struct declaration, to declare a ref struct or a readonly ref struct.
What is the out keyword
The out is a keyword in C# which is used for passing the arguments to methods as a reference type. It is generally used when a method returns multiple values. The out parameter does not pass the property.