C# Interview Questions and Answers (958) - Page 28

How to create an object without invoking constructor in c#.net?

FormatterServices.GetUninitializedObject(Type) is a method through which we can creates a new instance of the specified object type without invoking constructor. Even if the constructor is declared as private we can able to create object outside of the class. Because the new instance of the object is initialized to zero and no constructors are run.

Note: You cannot use the GetUninitializedObject method to create instances of types that derive from the ContextBoundObject class.
What are the major differences between C# and Java?

1)C# being a .NET language, supports language interoperability.This is not possible in Java.

2) The code written in C#, on compilation generates an ‘.exe’ or ‘.dll’ file which is also called Portable Executable file. These files contain MSIL (Microsoft Intermediate Language) code. As against this, the Java code on compilation generates a ‘.class’ file, which contains bytecode.

3)The portable executable file of C# can contain any number of classes, whereas, the ‘.class’ file in Java contains only one class.


4)The methods in C# are not virtual by default. On the contrary, methods in Java are virtual by default, which degrades the performance.

5)The classes in C# are grouped in Namespaces, whereas, classes in Java are grouped in Packages.
What makes a class abstract?

NOTE: This is objective type question, Please click question title for correct answer.
How to check if all array elements are strictly positive?

If you want to check whether everything is strictly positive, use:

bool allPositive = array.All(x => x > 0);

How to check if all array elements are non-negative?

If we actually want to check they're all non-negative (i.e. 0 is acceptable) use:

bool allNonNegative = array.All(x => x >= 0);

can one dll contain the compiled code of more than one programming language?

NOTE: This is objective type question, Please click question title for correct answer.
How to assign Multi Line String ?

You can use the @ symbol in front of a string

string str = @"Hello,
How are you
man";
What is difference between is and as operators in c#?

“is” operator is used to check the compatibility of an object with a given type and it returns the result as Boolean.
“as” operator is used for casting of object to a type or a class.
What is used in conversion where the conversion is defined between the expression and the type.

NOTE: This is objective type question, Please click question title for correct answer.
What is sealed Modifier

NOTE: This is objective type question, Please click question title for correct answer.
In c#, the attribute’s information for a Class can be retrieved at

NOTE: This is objective type question, Please click question title for correct answer.
What is inheritance hierarchy?

1. The class which derives functionality from a base class is called a derived class.
2. A derived class can also act as a base class for another class.
3. Thus it is possible to create a tree-like structure that illustrates the relationship between all related classes.
4. This structure is known as the inheritance hierarchy.
You need to write a multicast delegate that accepts a DateTime argument which code type you can choose

NOTE: This is objective type question, Please click question title for correct answer.
You need to create a method to clear a Queue named q.

NOTE: This is objective type question, Please click question title for correct answer.
you need to identify Is Always a number Is Always greater than a 65,535

NOTE: This is objective type question, Please click question title for correct answer.
Can we have Return Statement in Finally Block?

No,we can not write any Return Statement inside Finally Block.It will throw an error at the Complie-Time saying that:-

"Control cannot leave the body of a finally clause"

Meaning that finally block is only used for Releasing Objects or Calling any function other than Returning Some Value.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories