Jun 12

Basic C# Interview Questions and Answers

111. Which namespace enables multithreaded programming in XML?


112. Can we declare a block as static in c#?

No, because c# doesnot support static block, but it supports static method.

113. Can we declare a method as sealed?

In C# a method can’t be declared as sealed. However when we override a method in a derived class, we can declare the overridden method as sealed. By declaring it as sealed, we can avoid further overriding of this method.

114. What Command is used to implement properties in C#?

get & set access modifiers are used to implement properties in c#.

115. What is static member?

The member defined as static which can be invoked directly from the class level, rather than from its instance.

116. What is the syntax to inherit from a class in C#?

When a class is derived from another class, then the members of the base class become the members of the derived class.

The access modifier used while accessing members of the base class specifies the access status of the base class members inside the derived class.

The syntax to inherit a class from another class In C# is as follows:

class MyNewClass : MyBaseClass

117. What is a basic difference between the while loop and do while loop in C#?

The while loop tests its condition at the beginning, which means that the enclosed set of statements run for zero or more number of times if the condition evaluates to true. The do while loop iterates a set of statements at least once and then checks the condition at the end.

118. What is the main difference between a subprocedure and a function?

Subprocedures do not return a value, while functions do.

119. What are sealed classes in c#?

The sealed modifier is used to prevent derivation from a class.

A compile time error occurs if a sealed class is specified as the base class of another class.

120. What is the difference between class and an Interface?

Abstract classes can have implementations for some of its members, but the interface can’t have implementation for any of its members.

Interfaces cannot have fields where as an abstract class can have fields.

An interface can inherit from another interface only and cannot inherit from an abstract class, where as an abstract class can inherit from another abstract class or another interface.

A class can inherit from multiple interfaces at the same time, where as a class cannot inherit from multiple classes at the same time.

Abstract class members can have access modifiers where as interface members cannot have access modifiers.

121. What is the difference between an abstract method & virtual method?

An Abstract method does not provide an implementation and forces overriding to the deriving class (unless the deriving class also an abstract class), where as the virtual method has an implementation and leaves an option to override it in the deriving class. Thus Virtual method has an implementation & provides the derived class with the option of overriding it. Abstract method does not provide an implementation & forces the derived class to override the method.

122. What is Static Method?

It is possible to declare a method as Static provided that they don’t attempt to access any instance data or other instance methods.

123. What is a New modifier?

The new modifier hides a member of the base class. C# supports only hide by signature.

124. What are the advantages of get and set properties in C#?

The get property accessor is used to return the property value.

The set property accessor is used to assign a new value.

125. What are the difference between const and readonly?

A const can not be static, while readonly can be static.

A const need to be declared and initialized at declaration only, while a readonly can be initialized at declaration or by the code in the constructor.

A const’s value is evaluated at design time, while a readonly’s value is evaluated at runtime.

Permanent link to this article: http://zappmania.in/2014/06/12/basic-c-interview-questions-answers.htm

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.