C# interview questions and answers


46) How do you inherit a class into other class in C#?

Colon is used as inheritance operator in C#. Just place a colon and then the class name.


Example: public class DerivedClass : BaseClass

47) What is the difference between is and as operators in c#?

"is" operator is used to checking the compatibility of an object with a given type and it returns the result as Boolean.

"as" operator is used for casting of an object to a type or a class.

48) Is C# code is managed or unmanaged code?

Yes! C# is managed code because it uses Common language runtime(CLR) to compile C# code.

49) What are the differences between static, public and void in C#?

Public: The keyword public is an access modifier that tells the C# compiler that the Main method is accessible by anyone.

Static: The keyword static declares that the Main method is a global one and can be called without creating an instance of the class. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created.

Void: The keyword void is a type modifier that states that the Main method does not return any value.

50) What is the difference between methods – “System.Array.Clone()” and “System.Array.CopyTo()” ?

“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.

51) Explain Partial Class in C#?

Partial classes concept added in .Net Framework 2.0 & it allows us to split the business logic into multiple files with the same class name along with “partial” keyword.

     
51) What are the collection types can be used in C#?
Following are the collection types in C# -

1. ArrayList
2. Stack
3. Queue
4. SortedList
5. HashTable
6. Bit Array

Threading Questions


52) What is multitasking?

It is a feature of modern OS with which we can run multiple programs at the same time.
Example: Word, Excel etc.

53) What is Multi-Threading?

It is a subset of multitasking. Instead of switching between programs this feature switches between different part of the same program.
Example: Writing in MS-Word and It also checking spelling using spell-checker in the background

54) What is a thread?

It is a basic unit to which OS allocates processor time.
Example: .Net Framework program has at least 2 threads running one is the main program & Second is Garbage collector(GC).

55) How can we change the priority & what the levels of priority provided by .Net?

Syntax to change thread priority

Threading.Priority = Threadpriority.priorityUnit;
Levels of priority
1) Threadpriority.Highest (10)
2) Threadpriority.Abovenormal (7)
3) Threadpriority.Normal(5)
4) Threadpriority.Belownormal(3)
5) Threadpriority.Lowest(1)

56) How can you reference current thread of the method?

"Thread.Currentthread" refers to the current thread running the method.
It is public static property.

57) What is thread.sleep() in threading?

Thread execution can be paused by calling the Thread.Sleep method. This method takes on integer value that determines how long the thread should sleep
Example: Thread.currenttime.sleep(2000) // 2 Seconds

58) How can you make a thread sleep for infinite time?

Thread.sleep(System.Threading.Timeout.Infinite)

To interrupt this sleep method you can call-
Thread.interrupt method

59) What is suspend & Resume in Threading?

It is similar to sleep & interrupts. Suspend allow you to block thread until another thread calls thread.resume.

60) What is the difference between sleep & suspend?

The difference between sleep & suspend is that suspend does not immediately place a thread in a wait state. the thread does not suspend until the .Net runtime determines that it is in a safe place to suspend it. Sleep will immediately place a thread in a wait state.


« 1 2 3 4 5 »
 

Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.