FAQ'S ON DOT NET FRAME WORK PART TEN

1• What’s wrong with a line like this? DateTime.Parse(myString);

There IS nothing wrong with this declaration.Converts the specified string representation of a date and time to its DateTime equivalent.But If the string is not a valid DateTime,It throws an exception.

2• What are PDBs? Where must they be located for debugging to work?

A program database (PDB) files holds debugging and project state information that allows incremental linking of debug configuration of your program.There are several different types of symbolic debugging information. The default type for Microsoft compiler is the so-called PDB file. The compiler setting for creating this file is /Zi, or /ZI for C/C++(which creates a PDB file with additional information that enables a feature called ""Edit and Continue"") or a Visual Basic/C#/JScript .NET program with /debug.

A PDB file is a separate file, placed by default in the Debug project subdirectory, that has the same name as the executable file with the extension .pdb. Note that the Visual C++ compiler by default creates an additional PDB file called VC60.pdb for VisulaC++6.0 and VC70.PDB file for VisulaC++7.0. The compiler creates this file during compilation of the source code, when the compiler isn't aware of the final name of the executable. The linker can merge this temporary PDB file into the main one if you tell it to, but it won't do it by default. The PDB file can be useful to display the detailed stack trace with source files and line numbers.

3• What is FullTrust? Do GAC’ed assemblies have FullTrust?

Before the .NET Framework existed, Windows had two levels of trust for downloaded code. This old model was a binary trust model. You only had two choices: Full Trust, and No Trust. The code could either do anything you could do, or it wouldn't run at all.

The permission sets in .NET include FullTrust, SkipVerification, Execution, Nothing, LocalIntranet, Internet and Everything. Full Trust Grants unrestricted permissions to system resources. Fully trusted code run by a normal, nonprivileged user cannot do administrative tasks, but can access any resources the user can access, and do anything the user can do.

From a security standpoint, you can think of fully trusted code as being similar to native, unmanaged code, like a traditional ActiveX control.

GAC assemblies are granted FullTrust. In v1.0 and 1.1, the fact that assemblies in the GAC seem to always get a FullTrust grant is actually a side effect of the fact that the GAC lives on the local machine. If anyone were to lock down the security policy by changing the grant set of the local machine to something less than FullTrust, and if your assembly did not get extra permission from some other code group, it would no longer have FullTrust even though it lives in the GAC.

4• What does this do? gacutil /l | find /i "Corillian"

The Global Assembly Cache tool allows you to view and manipulate the contents of the global assembly cache and download cache.The tool comes with various optional params to do that.

""/l"" option Lists the contents of the global assembly cache. If you specify the assemblyName parameter(/l [assemblyName]), the tool lists only the assemblies matching that name.

5• What does this do .. sn -t foo.dll ?

Sn -t option displays the token for the public key stored in infile. The contents of infile must be previously generated using -p.

Sn.exe computes the token using a hash function from the public key. To save space, the common language runtime stores public key tokens in the manifest as part of a reference to another assembly when it records a dependency to an assembly that has a strong name. The -tp option displays the public key in addition to the token.

6• How do you generate a strong name?

.NET provides an utility called strong name tool. You can run this toolfrom the VS.NET command prompt to generate a strong name with an option "-k" and providing the strong key file name. i.e. sn- -k <>

7• What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?

The Debug build is the program compiled with full symbolic debug information and no optimization. The Release build is the program compiled employing optimization and contains no symbolic debug information. These settings can be changed as per need from Project Configuration properties. The release runs faster since it does not have any debug symbols and is optimized.

8• Explain the use of virtual, sealed, override, and abstract.

Abstract: The keyword can be applied for a class or method.

1. Class: If we use abstract keyword for a class it makes the class an abstract class, which means it cant be instantiated. Though it is not nessacary to make all the method within the abstract class to be virtual. ie, Abstract class can have concrete methods.

2. Method: If we make a method as abstract, we dont need to provide implementation of the method in the class but the derived class need to implement/override this method.

Sealed:

It can be applied on a class and methods. It stops the type from further derivation i.e no one can derive class from a sealed class,ie A sealed class cannot be inherited.A sealed class cannot be a abstract class.A compile time error is thrown if you try to specify sealed class as a base class.

When an instance method declaration includes a sealed modifier, that method is said to be a sealed method. If an instance method declaration includes the sealed modifier, it must also include the override modifier. Use of the sealed modifier prevents a derived class from further overriding the method For Egs: sealed override public void Sample() { Console.WriteLine("Sealed Method"); }

Virtual & Override: Virtual & Override keywords provides runtime polymorphism. A base class can make some of its methods as virtual which allows the derived class a chance to override the base class implementation by using override keyword.

For e.g. class Shape
{
int a
public virtual void Display()
{
Console.WriteLine("Shape");
}
}

class Rectangle:Shape
{
public override void Display()
{
Console.WriteLine("Derived");
}
}

9• Explain the importance and use of each, Version, Culture and PublicKeyToken for an assembly.

This three alongwith name of the assembly provide a strong name or fully qualified name to the assembly. When a assebly is referenced with all three.
PublicKeyToken: Each assembly can have a public key embedded in its manifest that identifies the developer. This ensures that once the assembly ships, no one can modify the code or other resources contained in the assembly.

Culture: Specifies which culture the assembly supports

Version: The version number of the assembly.It is of the following form major.minor.build.revision.

10 • Explain the differences between public, protected, private and internal. ?

These all are access modifier and they governs the access level. They can be applied to class, methods, fields.

Public: Allows class, methods, fields to be accessible from anywhere i.e. within and outside an assembly.

Private: When applied to field and method allows to be accessible within a class.

Protected: Similar to private but can be accessed by members of derived class also.

Internal: They are public within the assembly i.e. they can be accessed by anyone within an assembly but outside assembly they are not visible.

11• What is the difference between typeof(foo) and myFoo.GetType()?

Typeof is operator which applied to a object returns System.Type object. Typeof cannot be overloaded white GetType has lot of overloads.GetType is a method which also returns System.Type of an object. GetType is used to get the runtime type of the object.

Example from MSDN showing Gettype used to retrive type at untime:-

public class MyBaseClass: Object {
}
public class MyDerivedClass: MyBaseClass {
}
public class Test {
public static void Main() {
MyBaseClass myBase = new MyBaseClass();
MyDerivedClass myDerived = new MyDerivedClass();
object o = myDerived;
MyBaseClass b = myDerived;
Console.WriteLine("mybase: Type is {0}", myBase.GetType());
Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());
Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());
Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType());
}
}

/*

This code produces the following output.

mybase: Type is MyBaseClass
myDerived: Type is MyDerivedClass
object o = myDerived: Type is MyDerivedClass
MyBaseClass b = myDerived: Type is MyDerivedClass
*/

12 • Can "this" be used within a static method?

No 'This' cannot be used in a static method. As only static variables/methods can be used in a static method.

13 • What is the use of Internal keyword?

Internal keyword is one of the access specifier available in .Net framework , that makes a type visible in a given assembly , for e.g : a single dll can contain multiple modules , essentially a multi file assembly , but it forms a single binary component , so any type with internal keyword will be visible throughout the assembly and can be used in any of the modules .

14• What actually happes when you add a something to arraylistcollection ?

Following things will happen :

Arraylist is a dynamic array class in c# in System.Collections namespace derived from interfaces – ICollection , IList , ICloneable , IConvertible . It terms of in memory structure following is the implementation .

a. Check up the total space if there’s any free space on the declared list .
b. If yes add the new item and increase count by 1 .
c. If No Copy the whole thing to a temporary Array of Last Max. Size .
d. Create new Array with size ( Last Array Size + Increase Value )
e. Copy back values from temp and reference this new array as original array .
f. Must doing Method updates too , need to check it up .

RELATED POST

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART THREE

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FOUR

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FIVE

ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE

ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO

You can also learn the concept of frame work concept in detail with questions and answers in the following place.

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART ONE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TWO

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART THREE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FOUR

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FIVE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SIX

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SEVEN

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART EIGHT

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART NINE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TEN

No comments:

Post a Comment