Visit our sponsor Five Planet Juices  
Home
Microsoft Interview Process
Microsoft HR Questions
Technical Questions
Puzzles/Riddles
Resume Tips and Template
Discuss
Question to Interviewer
Interview Tips
Term Of Use
Site Feedback


General C# Questions

What is metadata? What information is stored in Metadata?
A bunch of tables, metadata is what makes assemble self-describe.

What are some of the Tables stored in metadata?
TypeDefinition table, TypeReference table
AssemblyRef table

What are the two basic kinds of types in .net framework?
Reference type (live in managed heap) and value type(live on stack). A class is a reference type. A struct is a value type.

What is boxing and unboxing?
Packing an value type and make a copy on the heap so it can be used by a function
That’s needs a reference type, unboxing is the opposite process.

What class does all classes implicitly inherited from?
System.Object

What is namespace, assembly?
Namespace is used to group related types. Assembly is a compilation unit.

What is global assembly cache, what is the purpose?
GAC(Global assembly Cache) is used to share assemblies across applications

What are Primitive types?
A: Primitive types has built-in compiler support, compiler knows how to cast. Etc.

What is reflection?
A way to figure out the type information at run time from an assembly’s metadata.

What is a delegate? 
Type safe call back mechanism.

Describe the accessibility modifier “protected internal”.
It is available to classes that are within the same assembly and derived from the specified base class. 
What does the term immutable mean?
The data value may not be changed.  Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory. 
What’s the difference between System.String and System.Text.StringBuilder classes?
System.String is immutable.  System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed. 
What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation.  Strings are immutable, so each time a string is changed, a new instance in memory is created.
Can you store multiple data types in System.Array?
No. 
What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array.  The CopyTo() method copies the elements into another existing array.  Both perform a shallow copy.  A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array.  A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.
How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.
 
What’s the .NET collection class that allows an element to be accessed using a unique key?
HashTable. 
Will the finally block get executed if an exception has not occurred?­
Yes. 
Can multiple catch blocks be executed for a single try statement?
No.  Once the proper catch block processed, control is transferred to the finally block (if there are any). 


Comments:

String Handling
By sribagy on Monday, October 02, 2006 (UMST)

Well,
 
I thought of this one as being tough to figure it out:

 

    string string1 = "value";
    object string2 = "value";
    if (string1 == string2)
      Console.WriteLine("==");
    else
      Console.WriteLine("not eq");
    string2 = string2 + "s";
    if (string1 == string2)   
      Console.WriteLine("==");   
    else
      Console.WriteLine("not eq");
    string2 = ((string)string2).Remove(((string)string2).Length-1, 1);
   
    if (string1 == string2)
      Console.WriteLine("==");
    else
      Console.WriteLine("not eq");

 
And the result is:
 
>==
>not eq
>not eq
 
The question would be:
 
“Why on the third "if", although the string IS the same, the answer is NOT EQUAL?”

Anyone??

I’ll come back with the answer…

Reply to this Comment

About references
By kev on Monday, October 16, 2006 (UMST)
the result will be "Not Equal" because operator "==" compares references and if it's possible to say so, reference is a kind of pointer to the object in the heap. You compare different objects which contain the same data, however these objects will be in different places of the heap. So their references will be different

Reply to this Comment

protected internal
By ivan on Monday, November 05, 2007 (UMST)

Actually, protected internal should be described as

"available to classes that are within the same assembly OR derived from the specified base class."

In Other words, "protected internal" classes are more visible than "protected" or "internal" classes.

Reply to this Comment

Can you store multiple data types in System.Array?
By ZeePrime on Wednesday, March 05, 2008 (UMST)

Can you store multiple data types in System.Array?
No.

 

This answer is not right.

Thanks to Object Incapsulation, I can have an Array of "Shapes".

Each of those shapes can be a Square, a Circle, a Triangle,...

 

They MUST inherit from the same defined base type "Shape",(or they MUST implement at least the same defined Interface, if this is an array of a given interface)

They are not strictly obliged to be of the same data type. If you ask

obj.GetType();

on all of them, you can have different answers.

 

They all answer true, to the question

obj is Shape

But they can anwer false to the question

obj[i].GetType() == obj[j].GetType()

 

I would have answered NO, with this or similar explanation.

Reply to this Comment

About references
By rprasad79 on Thursday, March 13, 2008 (UMST)
Then how come the first IF statement returns true. In that case also both the object are pointing to 2 different references. Can you please clarify me on the same

Reply to this Comment

Info about the string pooling
By onetime on Sunday, April 13, 2008 (UMST)
n C# strings are reference types. However, operator==() is overloaded for strings and compares string contents, not reference equality. String.Equals() also compares string contents. What makes strings unique is that string literals are pooled. For instance, if we have the following code: string s1 = "abc"; string s2 = "abc"; bool result = Object.ReferenceEquals(s1,s2); the value of result will be true. ReferenceEquals() is not lying here. s1 and s2 indeed reference the same object. The sysetm recognized that we have two equivalent string literals, and merged them into one. It can get away with it, because string objects are immutable. This check for duplicate string literals occurs when you code is JIT-compiled, i.e. converted from IL (intermediate language) to native (x86) machine codes. Thus, string literals are merged even when they are from different assemblies. Note, however, that merging process affects only string literals, not calculated strings. E.g., in the following code: string s1 = "abc"; string s2t = "ab"; string s2 = s2t + "c"; bool result = Object.ReferenceEquals(s1,s2); bool result2 = (s1==s2); value of result will be false. s1 and s2 are not merged, since s2 is not a literal. Nevertheless, the value of result2 is true, because for strings operator==() compares string contents, not object references.

Reply to this Comment

Prime Number Question
By nini1234 on Friday, October 31, 2008 (UMST)
public static int PrimeN(int n) { int count = 0; for (int i = 2; i <= n; i++) { int count2 = 0; for (int j = 1; j <= i; j++) { if (i%j==0) count2++; } if(count2==2) count++; count2 = 0; } return count; }

Reply to this Comment

Add Your Comment