C# Technical Interview Questions,FAQs and Answers

8/31/2009 No Comment
C# Interview Questions with Answers and FAQs helpful for clearing any C# Job Interview.

Is there any sample C# code for simple threading?
Some sample code follows: using System;
using System.Threading;
class ThreadTest
{
public void runme()
{
Console.WriteLine("Runme Called");
}
public static void Main(String[] args)
{
ThreadTest b = new ThreadTest();
Thread t = new Thread(new ThreadStart(b.runme));
t.Start();
}}

What is the difference between // comments, /* */ comments and /// comments?
Single-line, multi-line and XML documentation comments.

What is the difference between and XML documentation tag?

Single line code example and multiple-line code example.

Explain the three services model (three-tier application).
Presentation (UI), business (logic and underlying code) and data (from storage or other sources).

What are three test cases you should go through in unit testing?
Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).

How do you inherit from a class in C#?
Place a colon and then the name of the base class. Notice that it is double colon in C++.

How do I port "synchronized" functions from Visual J++ to C#?
Original Visual J++ code: public synchronized void Run()
{
// function body
}
Ported C# code: class C
{
public void Run()
{
lock(this)
{
// function body
}}
public static void Main() {}
}

Can I define a type that is an alias of another type (like typedef in C++)?
Not exactly. You can create an alias within a single file with the "using" directive: using System; using Integer = System.Int32; // alias
But you can't create a true alias, one that extends beyond the file in which it is declared. Refer to the C# spec for more info on the 'using' statement's scope.

Is it possible to have different access modifiers on the get/set methods of a property?
No. The access modifier on a property applies to both its get and set accessors. What you need to do if you want them to be different is make the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property.

Is it possible to have a static indexer in C#?
No. Static indexers are not allowed in C#.

Does C# support #define for defining global constants?
No. If you want to get something that works like the following C code:
#define A 1
use the following C# code: class MyConstants
{
public const int A = 1;
}
Then you use MyConstants.A where you would otherwise use the A macro.
Using MyConstants.A has the same generated code as using the literal 1.

Does C# support templates?
No. However, there are plans for C# to support a type of template known as a generic. These generic types have similar syntax but are instantiated at run time as opposed to compile time.

Does C# support parameterized properties?
No. C# does, however, support the concept of an indexer from language spec. An indexer is a member that enables an object to be indexed in the same way as an array. Whereas properties enable field-like access, indexers enable array-like access. As an example, consider the Stack class presented earlier. The designer of this class may want to expose array-like access so that it is possible to inspect or alter the items on the stack without performing unnecessary Push and Pop operations. That is, Stack is implemented as a linked list, but it also provides the convenience of array access.
Indexer declarations are similar to property declarations, with the main differences being that indexers are nameless (the name used in the declaration is this, since this is being indexed) and that indexers include indexing parameters. The indexing parameters are provided between square brackets.

Does C# support C type macros?
No. C# does not have macros. Keep in mind that what some of the predefined C macros (for example, __LINE__ and __FILE__) give you can also be found in .NET classes like System.Diagnostics (for example, StackTrace and StackFrame), but they'll only work on debug builds.
Can you store multiple data types in System.Array?
No.


Is it possible to inline assembly or IL in C# code?
No.


Can you declare the override method static while the original method is non-static?
No, you cannot, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override

Does C# support multiple inheritance?
No, use interfaces instead.

Can multiple catch blocks be executed?
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.

Can you override private virtual methods?
No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.

What is a pre-requisite for connection pooling?

Multiple processes must agree that they will share the same connection, where every parameter is the same,

What is the data provider name to connect to Access database?
Microsoft.Access.


Why does my Windows application pop up a console window every time I run it?

Make sure that the target type set in the project properties setting is set to Windows Application, and not Console Application. If you're using the command line, compile with /target:winexe & not target:exe.

What is the wildcard character in SQL?
Let us say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve La%.
What is the role of the DataReader class in ADO.NET connections?
It returns a read-only dataset from the data source when the command is executed.

What does the This window show in the debugger?
It points to the object that is pointed to by this reference. Object’s instance data is shown.

What is an interface class?
It is an abstract class with public abstract methods all of which must be implemented in the inherited classes.

What is a multicast delegate?
It is a delegate that points to and eventually fires off several methods.

Related Posts


No comments :

 

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