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.
What are properties
Properties are the special type of class members that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and helps to promote the flexibility and safety of methods. Encapsulation and hiding of information can also be achieved using properties. It uses pre-defined methods which are “get” and “set” methods which help to access and modify the properties.
Types of Accessors
Read and Write Properties: When property contains both get and set methods.
Read-Only Properties: When property contains only the get method.
Write Only Properties: When property contains only set method.
Auto Implemented Properties: When there is no additional logic in the property accessors, and it introduces in C# 3.0
What are partial classes
It provides a special ability to implement the functionality of a single class into multiple files and all these files are combined into a single class file when the application is compiled. A partial class is created by using a partial keyword. This keyword is also useful to split the functionality of methods, interfaces, or structure into multiple files.
What is Reflection
Reflection is the process of describing the metadata of types, methods, and fields in a code. The namespace System. Reflection enables you to obtain data about the loaded assemblies, the elements within them like classes, methods, and value types.
What is the difference between constant and read-only
In C#, a const keyword is used to declare constant fields and constant local. The value of the constant field is the same throughout the program or in other words, once the constant field is assigned the value of this field is not be changed. In C#, constant fields and locals are not variables, a constant is a number, string, null reference, boolean values. readonly keyword is used to declare a readonly variable. This readonly keyword shows that you can assign the variable only when you declare a variable or in a constructor of the same class in which it is declared.
What are jagged arrays
A jagged array is an array of arrays such that member arrays can be of different sizes. In other words, the length of each array index can differ. The elements of Jagged Array are reference types and initialized to null by default. Jagged Array can also be mixed with multidimensional arrays. Here, the number of rows will be fixed at the declaration time, but you can vary the number of columns.
What is System.Array.CopyTo()
The System.Array.CopyTo() technique makes a replica of the components into another existing array. It makes copies the components of one cluster to another existing array.