61) What you mean by boxing and unboxing in C#?
int myvar = 10;
object myObj = myvar;
int myvar2 = (int)myObj;
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.
Var myTestCategory = new { CategoryId = 1, CategoryName = “Category1”};
C# Compiler is – CSC.
65) Explain the types of unit test cases?
Below are the list of unit test case types –
- Positive Test cases
- Negative Test cases
- Exception Test cases
66) Explain Copy constructor in C#?
If the constructor contains the same class in the constructor parameter then it is called as copy constructor.
class MyClass
{
public string prop1, prop2;
public MyClass(string a, string b)
{
prop1 = a;
prop2 = b;
}
public MyClass(MyClass myobj) // Copy Constructor
{
prop1 = myobj.prop1;
prop2 = myobj.prop2;
}
}
67) 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.
class MyClass
{
public string prop1, prop2;
public MyClass(string a, string b)
{
prop1 = a;
prop2 = b;
}
Static MyClass()
{
Console.WriteLine(“Static Constr Test”);
}
public MyClass(MyClass myobj) // Copy Constructor
{
prop1 = myobj.prop1;
prop2 = myobj.prop2;
}
}
68) Which string method is used for concatenation of two strings in c#?
“Concat” method of String class is used to concatenate two strings. For example,
string.Concat(firstStr, secStr)
69) 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. For example,
class MyCollection<T>
{
private T[] myArr = new T[100];
public T this[int t]
{
get
{
return myArr[t];
}
set
{
myArr[t] = value;
}
}
}
70) What are the collection types can be used in C#?
Below are the collection types in C# -
- ArrayList
- Stack
- Queue
- SortedList
- HashTable
- Bit Array
71) Explain Attributes in C#?
- Attributes are used to convey the info for runtime about the behavior of elements like – “methods”, “classes”, “enums” etc.
- Attributes can be used to add metadata like – comments, classes, compiler instruction etc.
72) List out the pre defined attributes in C#?
Below are the predefined attributes in C# -
- Conditional
- Obsolete
- Attribute Usage
73) 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.
74) List out the states of a thread in C#?
Below are the states of thread –
- Unstarted State
- Ready State
- Not Runnable State
- Dead State
75) Explain the methods and properties of Thread class in C#?
Below are the methods and properties of thread class –
- CurrentCulture
- CurrentThread
- CurrentContext
- IsAlive
- IsThreadPoolThread
- IsBackground
- Priority