CSharp Flashcards
Explain Indexers in C#?
Indexers are used for allowing the classes to be indexed like arrays. Indexers will resemble the property structure but only difference is indexer’s accessors will take parameters.
What is the difference between “out” and “ref” parameters in C#
“out” parameter can be passed to a method and it need not be initialized where as “ref” parameter has to be initialized before it is used.
What is Constructor Overloading in C# .net ?
In Constructor overloading, n number of constructors can be created for the same class. But the signatures of each constructor should vary.
What is Operator Overloading in C# .net ?
We had seen function overloading in the previous example. For operator Overloading, we will have a look at the example given below. We had defined a class rectangle with two operator overloading methods.
Name the compiler of C#?
C# Compiler is – CSC.
What is Unboxing in C#
UnBoxing – It’s completely opposite to boxing. It’s the process of converting reference type to value type. For example, int myvar2 = (int)myObj;
Explain Overloading in C# ?
When methods are created with the same name, but with different signature its called overloading.
Explain Static constructor in C#?
If the constructor is declared as static then it will be invoked only once for all number of instances of a class. Static constructor will initialize the static fields of a class.
What is the difference between methods – “System.Array.Clone()” and “System.Array.CopyTo()” in C#?
“CopyTo()” method can be used to copy the elements of one array to other: “Clone()” method is used to create a new array to contain all the elements which are in the original array.
What is Sealed Classes in c# ?
If a class is defined as Sealed, it cannot be inherited in derived class
Which are the loop types available in C#?
For, While, Do..While
What is Abstract Class in C#?
If we don’t want a class to be instantiated, define the class as abstract. An abstract class can have abstract and non abstract classes. If a method is defined as abstract, it must be implemented in derived class.
Different Types of C# overloading
Constructor, Function, Operator
What is an Object?
An object is an instance of a class. It contains real values instead of variables.
Can a “try” block exist without a “catch” block
Yes, but we must have a “finally” block
Explain Partial Class in C#?
Partial classes concept added in .Net Framework 2.0 and it allows us to split the business logic in multiple files with the same class name along with “partial” keyword.
Explain the types of unit test cases?
Positive Test Cases, Negative Test Cases, Exception Test Cases
What is a delegate in C#
Delegates are type safe pointers unlike function pointers as in C++. Delegate is used to represent the reference of the methods of some return type and parameters.
What are C# reference types
class, string, interface, object
What are the uses of delegates in C#
Callback Mechanism, Asynchronuous Processing, Abstract and Encapsulate method; Multicasting
What is Thread in C#?
Thread is an execution path of a program. Thread is used to define the different or unique flow of control. If our application involves some time consuming processes then it’s better to use Multithreading., which involves multiple threads.
What are the differences between events and delegates in C#?
Main difference between event and delegate is event will provide one more of encapsulation over delegates. So when you are using events destination will listen to it but delegates are naked, which works in subscriber/destination model.
Define Property in C# ?
Properties are a type of class member, that are exposed to the outside world as a pair of Methods. For example, for the static field Minsalary, we will Create a property as shown below. Public static double MinSalary{get { return minimumSalary;} set { minimumSalary = value}}
Why to use lock statement in C#?
Lock will make sure one thread will not intercept the other thread which is running the part of code. So lock statement will make the thread wait, block till the object is being released.
What is an Interface in C# ?
An interface is similar to a class with method signatures. There wont be any implementation of the methods in an Interface. Classes which implement interface should have an implementation of methods defined in the abstract class.
What are the features of C#
Constructors and Destructors; Properties; Passing Parameters; Arrays; Main, XML Documentation; Indexers
Explain Hashtable in C#?
It is used to store the key/value pairs based on hash code of the key. Key will be used to access the element in the collection
What are 2 types of errors in c#
Compile time error; Run time error
What is a const in C#
Keyword used for making an entity constant; the value can not be reassigned
List out the pre defined attributes in C#?
Conditional, Obsolete, Attribute Usage
What is the difference between “StringBuilder” and “String” in C#
StringBuilder is mutable, which means once object for the stringbuilder is created it can be modified either using Append, Remove or Replace. String is immutable which means we cannot modify the string object and will always create a new object in memory of type string