C# Interview Questions And Answers Part - 7
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.
Describe the accessibility modifier protected internal?
It is available to derived classes and classes within the same Assembly (and naturally from the base class it is declared in).
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.
How does one compare strings in C#?
In the past, you had to call .ToString() on the strings when using the == or != operators to compare the strings' values. That will still work, but the C# compiler now automatically compares the values instead of the references when the == or != operators are used on string types. If you actually do want to compare references, it can be done as follows: if ((object) str1 == (object) str2) { ... } Here's an example showing how string compares work: using System;
public class StringTest
{
public static void Main(string[] args)
{
Object nullObj = null;
Object realObj = new StringTest();
int i = 10;
Console.WriteLine("Null Object is [" + nullObj + "]n" +
"Real Object is [" + realObj + "]n" +
"i is [" + i + "]n");
// Show string equality operators
string str1 = "foo";
string str2 = "bar";
string str3 = "bar";
Console.WriteLine("{0} == {1} ? {2}", str1, str2, str1 == str2 );
Console.WriteLine("{0} == {1} ? {2}", str2, str3, str2 == str3 );
}
}
Output: Null Object is []
Real Object is [StringTest]
i is [10]
foo == bar ? False
bar == bar ? True
What does assert() do?
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
How do I get deterministic finalization in C#?
In a garbage collected environment, it's impossible to get true determinism. However, a design pattern that we recommend is implementing IDisposable on any class that contains a critical resource. Whenever this class is consumed, it may be placed in a using statement, as shown in the following example:
using(FileStream myFile = File.Open(@"c:temptest.txt",
FileMode.Open))
{
int fileOffset = 0;
while(fileOffset <>
How can I get around scope problems in a try/catch?
If you try to instantiate the class inside the try, it'll be out of scope when you try to access it from the catch block. A way to get around this is to do the following: Connection conn = null;
try
{
conn = new Connection();
conn.Open();
}
finally
{
if (conn != null) conn.Close();
}
By setting it to null before the try block, you avoid getting the CS0165 error (Use of possibly unassigned local variable 'conn').
Why do I get an error (CS1006) when trying to declare a method without specifying a return type?
If you leave off the return type on a method declaration, the compiler thinks you are trying to declare a constructor. So if you are trying to declare a method that returns nothing, use void. The following is an example: // This results in a CS1006 error public static staticMethod (mainStatic obj) // This will work as wanted public static void staticMethod (mainStatic obj)
Page numbers : 1 2 3 4 5 6 7 8 9 10 11 12 13