Programming Tutorials on XHTML, CSS, JavaScript, JQuery, JSON, Python, Django, Amazon Web Services, ASP.NET, Web Forms, and SQL
Sunday, July 1, 2012
C# interview questions with answers, Part 3
C# developer interview questions and answers.
What is the difference between Finalize() and Dispose()?
Dispose() is called by as an indication for an object to release any unmanaged resources it has held.
Finalize() is used for the same purpose as dispose however finalize doesn’t assure the garbage collection of an object.
Dispose() operates determinalistically due to which it is generally preferred.
What is the difference between Debug.Write and Trace.Write? When should each be used?
Debug.Write: Debug Mode, Release Mode, It used while debuging a project.
Trace.write: Release Mode, It used in Released verion of Applications.
Explain the use of virtual, sealed, override, and abstract.
The virtual keyword enables a class to be overridden. If it has to be prevented from being overridden, then the sealed keyword needs to be used. If the keyword virtual is not used, members of the class can even then be overridden. However, its usage is advised for making the code meaningful.
The override keyword is used to override the virtual method in the base class. Abstract keyword is used to modify a class, method or property declaration. You cannot instantiate an abstract class or make calls to an abstract method directly.
An abstract virtual method means that the definition of the method needs to be given in the derived class.
What benefit do you get from using a Primary Interop Assembly (PIA)?
A primary interop assembly contains type definitions (as metadata) of types implemented with COM. Only a single PIA can exist, which needs to be signed with a strong name by the publisher of the COM type library.
One PIA can wrap multiple versions of the same type library.
A COM type library imported as an assembly can be a PIA only if it has been signed and published by the same publisher.
Therefore, only the publisher of a type library can produce a true PIA, that can be considered as the unit of an official type definition for interoperating with the underlying COM types.
Explain the use of static members with example using C#.NET.
Static members are not associated with a particular instance of any class.
They need to be qualified with the class name to be called.
Since they are not associated with object instances, they do not have access to non-static members.
i.e.: "this" cannot be used, which represents the current object instance.
C# interview questions with answers, Part 2
C# developer interview questions with answers.
What is a delegate?
- A strongly typed function pointer.
- A light weight thread or process that can call a single method.
- A reference to an object in a different process.
- An inter-process message channel.
Answer :
1. A strongly typed function pointer.
How does assembly versioning in .NET prevent DLL Hell?
- The runtime checks to see that only one version of an assembly is on the machine at any one time.
- .NET allows assemblies to specify the name AND the version of any assemblies they need to run.
- The compiler offers compile time checking for backward compatibility.
- It doesn't.
Answer :
2. .NET allows assemblies to specify the name AND the version of any assemblies they need to run.
Which .Gang of Four. design pattern is shown below?
public class A {
private A instance;
private A() {
}
public
static A Instance {
get
{
if ( A == null )
A = new A();
return instance;
}
}
}
- Factory
- Abstract Factory
- Singleton
- Builder
Answer :
3. Singleton
In the NUnit test framework, which attribute must adorn a test class in order for it to be picked up by the NUnit GUI?
- TestAttribute
- TestClassAttribute
- TestFixtureAttribute
- NUnitTestClassAttribute
Answer :
3. TestFixtureAttribute
Which of the following operations can you NOT perform on an ADO.NET DataSet?
- A DataSet can be synchronised with the database.
- A DataSet can be synchronised with a RecordSet.
- A DataSet can be converted to XML.
- You can infer the schema from a DataSet.
Answer :
2. A DataSet can be synchronised with a RecordSet.
In Object Oriented Programming, how would you describe encapsulation?
- The conversion of one type of object to another.
- The runtime resolution of method calls.
- The exposition of data.
- The separation of interface and implementation.
Answer :
4. The separation of interface and implementation.
C# interview questions with answers, Part 1
C# developer interview questions with answers.
The C# keyword .int. maps to which .NET type?
Answer :
2. System.Int32
Which of these statements correctly declares a two-dimensional array in C#?
Answer :
1. int[,] myArray;
Which of these string definitions will prevent escaping on backslashes in C#?
3. string s = @.n Test string.;
If a method is marked as protected internal who can access it?
Answer :
4. Classes within the same assembly, and classes derived from the declaring class.
What is boxing?
Answer :
4. Encapsulating a copy of a value type in an object.
What compiler switch creates an xml file from the xml comments in the files in an assembly?
What is a satellite Assembly?
The C# keyword .int. maps to which .NET type?
- System.Int16
- System.Int32
- System.Int64
- System.Int128
Answer :
2. System.Int32
Which of these statements correctly declares a two-dimensional array in C#?
- int[,] myArray;
- int[][] myArray;
- int[2] myArray;
- System.Array[2] myArray;
Answer :
1. int[,] myArray;
Which of these string definitions will prevent escaping on backslashes in C#?
- string s = #.n Test string.;
- string s = ..n Test string.;
- string s = @.n Test string.;
- string s = .n Test string.;
3. string s = @.n Test string.;
If a method is marked as protected internal who can access it?
- Classes that are both in the same assembly and derived from the declaring class.
- Only methods that are in the same class as the method in question.
- Internal methods can be only be called using reflection.
- Classes within the same assembly, and classes derived from the declaring class.
Answer :
4. Classes within the same assembly, and classes derived from the declaring class.
What is boxing?
- Encapsulating an object in a value type.
- Encapsulating a copy of an object in a value type.
- Encapsulating a value type in an object.
- Encapsulating a copy of a value type in an object.
Answer :
4. Encapsulating a copy of a value type in an object.
What compiler switch creates an xml file from the xml comments in the files in an assembly?
- /text
- /doc
- /xml
- /help
Answer :
2. /doc
2. /doc
What is a satellite Assembly?
- A peripheral assembly designed to monitor permissions requests from an application.
- Any DLL file used by an EXE file.
- An assembly containing localized resources for another assembly.
- An assembly designed to alter the appearance or .skin. of an application.
Answer :
3. An assembly containing localized resources for another assembly.
3. An assembly containing localized resources for another assembly.
How to count vowels in a string using c#
You can find vowel's occurrence in a string by many ways, one of them is below :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
string s1 = "This is test string";
int count = findVowel(s1);
Console.WriteLine( "No of vowels in '" + s1 + "' is : " + count);
}
private static int findVowel(string str)
{
int count = 0;
for (int i = 0; i < str.Length - 1; i++)
{
switch (str[i])
{
case 'a':
count++;
break;
case 'A':
count++;
break;
case 'e':
count++;
break;
case 'E':
count++;
break;
case 'i':
count++;
break;
case 'I':
count++;
break;
case 'o':
count++;
break;
case 'O':
count++;
break;
case 'u':
count++;
break;
case 'U':
count++;
break;
} // end switch
} // end for loop
return count;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
string s1 = "This is test string";
int count = findVowel(s1);
Console.WriteLine( "No of vowels in '" + s1 + "' is : " + count);
}
private static int findVowel(string str)
{
int count = 0;
for (int i = 0; i < str.Length - 1; i++)
{
switch (str[i])
{
case 'a':
count++;
break;
case 'A':
count++;
break;
case 'e':
count++;
break;
case 'E':
count++;
break;
case 'i':
count++;
break;
case 'I':
count++;
break;
case 'o':
count++;
break;
case 'O':
count++;
break;
case 'u':
count++;
break;
case 'U':
count++;
break;
} // end switch
} // end for loop
return count;
}
}
}
Hit Like, if it help full to you... :)
const and readonly in C# .NET
What is the difference between const and readonly in C#.NET?
The read only can be modified by the class it is contained in. However, the const cannot be modified. It needs to be instantiated only at the compile time.
Subscribe to:
Posts (Atom)