C# Concepts,Interview Questions and Answers

7/19/2009 2 Comments

Microsoft C#.NET Frequently Asked Questions, C#.NET Concepts, Answers and Solutions.

We are trying to provide some useful Interview Questions and Answers collected from top companies in India like IBM , TCS, Accenture and Wipro. The answers are explained in detail. Please use the comment section for more.

Explain in detail what happens in memory when you Box and Unbox a value-type in C#.NET? 
Answer : Boxing is a process that converts a value-type to a reference-type, thus storing the object on the heap whereas Unboxing converts a reference-type to a value-type, thus storing the value on the stack.

What is the main difference between directcast and ctype. Explain with the help of examples 
Answer : DirectCast requires the run-time type of an object variable to be the same as the specified type.The run-time performance ofDirectCast is better than that of CType, if the specified type and the run-time typeof the expression are the same. Ctype works fine if there is a valid conversion defined between the expression and the type.

The difference between the two keywords is that CType succeeds as long as there is a valid conversion defined between the expression and the type, whereas DirectCast requires the run-time type of an object variable to be the same as the specified type. If the specified type and the run-time type of the expression are the same, however, the run-time performance of DirectCast is better than that of CType.

We will explain with the help of an example the difference between a ctype and directcast.
We have seen in the preceding example, the run-time type of Q is Double. CType succeeds because Double can be converted to Integer, but DirectCast fails because the run-time type of Q is not already Integer
ctype(123.34,integer) - should it throw an error? Now we will see why or why not?


It would work fine. As the runtime type of 123.34 would be double, and Double can be converted to Integer.

the ctype(123.34,integer) will work fine no errors 
directcast(123.34,integer) - should it throw an error? Why or why not?
It would throw an InvalidCast exception as the runtime type of 123.34 (double) doesnt match with Integer.


Which control cannot be placed in MDI?
Answer : The controls that do not have events.

What is the difference between proc. sent BY VAL and BY SUB? 
Answer : BY VAL: changes will not be reflected back to the variable.
By REF: changes will be reflected back to that variable.( same as & symbol in c, c++)


What is the main difference between a sub and a function.
Answer :  A Sub does not return anything whereas a Function returns something.

A Sub Procedure is a method will not return a value
-A sub procedure will be defined with a “Sub” keyword

Sub ShowName(ByVal myName As String)
Console.WriteLine(”My name is: ” & myName)
End Sub

-A function is a method that will return value(s).
-A function will be defined with a “Function” keyword

Function FindSum(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
Dim sum As Integer = num1 + num2
Return sum
End Function]

What is the difference between imperative and interrogative code. 
Answer : There are imperative and interrogative functions. Imperative functions are the one which return a value while the interrogative functions do not return a value.


Explain what is the difference between a manifest & metadata.
Answer :  Manifest is metadata about assemblies. Metadata is machine-readable information about a resource, or “”data about data.” In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information.

Manifest: Manifest describes assembly itself. Assembly Name, version number, culture, strong name, list of all files, Type references, and referenced assemblies.
Metadata: Metadata describes contents in an assembly classes, interfaces, enums, structs, etc., and their containing namespaces, the name of each type, its visibility/scope, its base class, the nterfaces it implemented, its methods and their scope, and each method’s parameters, type’s properties, and so on.

What is the difference between value and reference type. what are value types and reference types?
Answer : Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort
Value types are stored in the Stack
Reference type - class, delegate, interface, object, string
Reference types are stored in the Heap

What are the two kinds of properties. Two types of properties in .Net: Get and Set
Explain constructor.

Constructor is a method in the class which has the same name as the class (in VB.Net its New()). It initializes the member attributes whenever an instance of the class is created.
Describe ways of cleaning up objects.

There is a perfect tool provide by .net frameworks calls Garbage collector, where by mean of GC we can clean up the object and reclaim the memory. The namespace used is System.GC

the run time will maintain a service called as garbage collector. This service will take care of deallocating memory corresponding to objects. it works as a thread with least priority. when application demands for memory the run-time will take care of setting the high priority for the garbage collector, so that it will be called for execution and memory will be released. the programmer can make a call to garbage collector by using GC class in system name space.

How can you clean up objects holding resources from within the code?
Answer : Call the dispose method from code for clean up of objects

Which controls do not have events?
Answer : Timer control.


What is the maximum size of the textbox?
Answer : 65536 is the maximum size. 


Which property of the textbox cannot be changed at run-time in C#.NET?
Answer : Locked Property cannot be changed at run-time.


We hope we will publish more of descriptive question and answers in the future which will help job seekers to get a comprehensive coverage. Thank you.

2 comments :

  1. Ӏt'ѕ verty straightforward tо find ouut аny matter оn web as compared to
    books, аs I found tyis paragraph at thiѕ web site.

    ReplyDelete
  2. Hеllo, after reading this amazing article і am too hаppy
    to share mmy experience һere ԝith friends.

    ReplyDelete

 

Aired | The content is copyrighted and may not be reproduced on other websites. | Copyright © 2009-2016 | All Rights Reserved 2016

Contact Us | About Us | Privacy Policy and Disclaimer