Você está na página 1de 57

C# Frequently Asked Interview Questions and Answers 1.

Whats the implicit name of the parameter that gets passed into the class set method? Value, and its datatype depends on whatever variable were changing. 2. How do you inherit from a class in C#? Place a colon and then the name of the base class. Notice that its double colon in C++. 3. Does C# support multiple inheritance? No, use interfaces instead. 4. When you inherit a protected class-level variable, who is it available to? Classes in the same namespace. 5. Are private class-level variables inherited? Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are. 6. Describe the accessibility modifier protected internal. Its available to derived classes and classes within the same Assembly (and naturally from the base class its declared in). 7. C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write? Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if theres no implementation in it. 8. Whats the top .NET class that everything is derived from? System.Object. 9. Hows method overriding different from overloading? When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class. 10. What does the keyword virtual mean in the method definition? The method can be over-ridden. 11. Can you declare the override method static while the original method is non-static? No, you cant, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override. 12. 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.

13. Can you prevent your class from being inherited and becoming a base class for some other classes? Yes, thats what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. Its the same concept as final class in Java. 14. Can you allow class to be inherited, but prevent the method from being overridden? Yes, just leave the class public and make the method sealed. 15. Whats an abstract class? A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, its a blueprint for a class without any implementation. 16. When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)? When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden. 17. Whats an interface class? Its an abstract class with public abstract methods all of which must be implemented in the inherited classes. 18. Why cant you specify the accessibility modifier for methods inside the interface? They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, its public by default. 19. Can you inherit multiple interfaces? Yes, why not. 20. And if they have conflicting method names? Its up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares youre okay. 21. Whats the difference between an interface and abstract class? In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes. 22. How can you overload a method? Different parameter data types, different number of parameters, different order of parameters. 23. If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited

constructor to an arbitrary base constructor? Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class. 24. Whats the difference between System.String and System.StringBuilder classes? System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed. 25. Whats the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time its being operated on, a new instance is created. 26. Can you store multiple data types in System.Array? No. 27. Whats the difference between the System.Array.CopyTo() and System.Array.Clone()? The first one performs a deep copy of the array, the second one is shallow. 28. How can you sort the elements of the array in descending order? By calling Sort() and then Reverse() methods. 29. Whats the .NET datatype that allows the retrieval of data by a unique key? ashTable. 30. Whats class SortedList underneath? A sorted HashTable. 31. Will finally block get executed if the exception had not occurred? Yes. 32. Whats the C# equivalent of C++ catch (), which was a catch-all statement for any possible exception? A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}. 33. 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. 34. Why is it a bad idea to throw your own exceptions? Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project. 35. Whats a delegate? A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.

36. Whats a multicast delegate? Its a delegate that points to and eventually fires off several methods. 37. Hows the DLL Hell problem solved in .NET? Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly. 38. What are the ways to deploy an assembly? An MSI installer, a CAB archive, and XCOPY command. 39. Whats a satellite assembly? When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies. 40. What namespaces are necessary to create a localized application? System.Globalization, System.Resources. 41. Whats the difference between // comments, /* */ comments and /// comments? Single-line, multi-line and XML documentation comments. 42. How do you generate documentation from the C# file commented properly with a command-line compiler? Compile it with a /doc switch. 43. Whats the difference between and XML documentation tag? Single line code example and multiple-line code example. 44. Is XML case-sensitive? Yes, so and are different elements. 45. What debugging tools come with the .NET SDK? CorDBG command-line debugger, and DbgCLR graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch. 46. What does the This window show in the debugger? It points to the object thats pointed to by this reference. Objects instance data is shown. 47. 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. 48. Whats the difference between the Debug class and Trace class? Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

49. Why are there five tracing levels in System.Diagnostics.TraceSwitcher? The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities. 50. Where is the output of TextWriterTraceListener redirected? To the Console or a text file depending on the parameter passed to the constructor. 51. How do you debug an ASP.NET Web application? Attach the aspnet_wp.exe process to the DbgClr debugger. 52. 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). 53. Can you change the value of a variable while debugging a C# application? Yes, if you are debugging via Visual Studio.NET, just go to Immediate window. 54. Explain the three services model (three-tier application). Presentation (UI), business (logic and underlying code) and data (from storage or other sources). 55. What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but its a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines. 56. Whats the role of the DataReader class in ADO.NET connections? It returns a readonly dataset from the data source when the command is executed. 57. What is the wildcard character in SQL? Lets 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%. 58. Explain ACID rule of thumb for transactions. Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no in-between case where something has been updated and something hasnt), Isolated (no transaction sees the intermediate results of

the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after). 59. What connections does Microsoft SQL Server support? Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords). 60. Which one is trusted and which one is untrusted? Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction. 61. Why would you use untrusted verificaion? Web Services might use it, as well as nonWindows applications. 62. What does the parameter Initial Catalog define inside Connection String? The database name to connect to. 63. Whats the data provider name to connect to Access database? Microsoft.Access. 64. What does Dispose method do with the connection object? Deletes it from the memory. 65. 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, including the security settings.

1. Whats the implicit name of the parameter that gets passed into the class set method? Value, and its datatype depends on whatever variable were changing.

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

3. When you inherit a protected class-level variable, who is it available to? Classes in the same namespace.

4. Are private class-level variables inherited? Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

5. Describe the accessibility modifier protected internal. Its available to derived classes and classes within the same Assembly (and naturally from the base class its declared in).

6. C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write? Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if theres no implementation in it.

7. Whats the top .NET class that everything is derived from? System.Object.

8. Hows method overriding different from overloading? When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

9. What does the keyword virtual mean in the method definition? The method can be over-ridden.

10. Can you declare the override method static while the original method is nonstatic? No, you cant, the signature of the virtual method must remain the same, only the

keyword virtual is changed to keyword override.

11. 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.

12. Can you prevent your class from being inherited and becoming a base class for some other classes? Yes, thats what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. Its the same concept as final class in Java.

13. Can you allow class to be inherited, but prevent the method from being overridden? Yes, just leave the class public and make the method sealed.

14. Whats an abstract class? A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, its a blueprint for a class without any implementation.

15. When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)? When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.

16. Whats an interface class? Its an abstract class with public abstract methods all of which must be implemented in the inherited classes.

17. Why cant you specify the accessibility modifier for methods inside the interface? They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, its public by default.

18. And if they have conflicting method names? Its up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares youre okay.

19. Whats the difference between an interface and abstract class? In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

20. How can you overload a method? Different parameter data types, different number of parameters, different order of parameters.

21. If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor? Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

22. Whats the difference between System.String and System.StringBuilder classes? System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

23. Whats the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time its being operated on, a new instance is created.

24. Can you store multiple data types in System.Array? No.

25. Whats the difference between the System.Array.CopyTo() and System.Array.Clone()? The first one performs a deep copy of the array, the second one is shallow.

26. How can you sort the elements of the array in descending order? By calling Sort() and then Reverse() methods.

27. Whats the .NET datatype that allows the retrieval of data by a unique key? HashTable.

28. Whats class SortedList underneath? A sorted HashTable.

29. Will finally block get executed if the exception had not occurred? Yes. 30. 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.

31. Why is it a bad idea to throw your own exceptions?

Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.

32. Whats a delegate? A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.

33. Whats a multicast delegate? Its a delegate that points to and eventually fires off several methods.

34. Hows the DLL Hell problem solved in .NET? Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.

35. What are the ways to deploy an assembly? An MSI installer, a CAB archive, and XCOPY command.

36. Whats a satellite assembly? When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

37. What namespaces are necessary to create a localized application? System.Globalization, System.Resources.

38. How do you generate documentation from the C# file commented properly with a command-line compiler? Compile it with a /doc switch.

39. Whats the difference between and XML documentation tag?

Single line code example and multiple-line code example.

40. Is XML case-sensitive? Yes, so and are different elements.

41. What debugging tools come with the .NET SDK? CorDBG command-line debugger, and DbgCLR graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.

42. What does the This window show in the debugger? It points to the object thats pointed to by this reference. Objects instance data is shown.

43. 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.

44. Whats the difference between the Debug class and Trace class? Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

45. Why are there five tracing levels in System.Diagnostics.TraceSwitcher? The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.

46. Where is the output of TextWriterTraceListener redirected? To the Console or a text file depending on the parameter passed to the constructor.

47. How do you debug an ASP.NET Web application? Attach the aspnet_wp.exe process to the DbgClr debugger.

48. 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).

49. Can you change the value of a variable while debugging a C# application? Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

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

51. What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but its a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.

52. Whats 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.

53. What is the wildcard character in SQL? Lets 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%.

54. Explain ACID rule of thumb for transactions. Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no in-between case where something has been updated and something hasnt), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).

55. What connections does Microsoft SQL Server support? Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).

56. Which one is trusted and which one is untrusted? Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.

57. Why would you use untrusted verificaion? Web Services might use it, as well as non-Windows applications.

58. What does Dispose method do with the connection object? Deletes it from the memory.

59. 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, including the security settings.

1. How big is the datatype int in .NET? 32 bits.

2. How big is the char? 16 bits (Unicode).

3. How do you initiate a string without escaping each backslash? Put an @ sign in front of the double-quoted string.

4. What are valid signatures for the Main function? l public static void Main() l public static int Main()

l public static void Main( string[] args ) l public static int Main(string[] args )

5. How do you initialize a two-dimensional array that you dont know the dimensions of? l int [, ] myArray; //declaration l myArray= new int [5, 8]; //actualinitialization

6. Whats the access level of the visibility type internal? Current assembly.

7. Whats the difference between struct and class in C#? l Structscannot be inherited. l Structsare passed by value, not by reference. l Struct is stored on the stack, not the heap.

8. Explain encapsulation. The implementation is hidden, the interface is exposed.

9. What data type should you use if you want an 8-bit value thats signed? sbyte.

10. Speaking of Boolean data types, whats different between C# and C/C++? Theres no conversion between 0 and false, as well as any other number and true, like in C/C++.

11. Where are the value-type variables allocated in the computer RAM? Stack.

12. Where do the reference-type variables go in the RAM? The references go on the stack, while the objects themselves go on the heap.

13. What is the difference between the value-type variables and reference-type variables in terms of garbage collection? The value-type variables are not garbage-collected, they just fall off the stack when they fall out of scope, the reference-type objects are picked up by GC when their references go null.

14. How do you convert a string into an integer in .NET? Int32.Parse(string)

15. How do you box a primitive data type variable? Assign it to the object, pass an object.

16. Why do you need to box a primitive variable? To pass it by reference.

17. Whats the difference between Java and .NET garbage collectors? Sun left the implementation of a specific garbage collector up to the JRE developer, so their performance varies widely, depending on whose JRE youre using. Microsoft standardized on their garbage collection.

18. How do you enforce garbage collection in .NET? System.GC.Collect();

19. Can you declare a C++ type destructor in C# like ~MyClass()? Yes, but whats the point, since it will call Finalize(), and Finalize() has no guarantees when the memory will be cleaned up, plus, it introduces additional load on the garbage collector.

20. Whats different about namespace declaration when comparing that to package declaration in Java? No semicolon.

21. Whats the difference between const and readonly? You can initialize readonly variables to some runtime values. Lets say your program uses current date and time as one of the values that wont change. This way you declare public readonly string DateT = new DateTime().ToString().

22. What does \a character do? On most systems, produces a rather annoying beep.

23. Can you create enumerated data types in C#? Yes.

24. Whats different about switch statements in C#? No fall-throughs allowed.

25. What happens when you encounter a continue statement inside the for loop? The code for the rest of the loop is ignored, the control is transferred back to the beginning of the loop.

26. Is goto statement supported in C#? How about Java? Gotos are supported in C#to the fullest. In Java goto is a reserved keyword that provides absolutely no functionality

C# Interview Questions | C Sharp Interview Questions


1) Explain about C#? C # is also known as c sharp. It is a programming language introduced by Microsoft. C# contains features similar to Java and C++. It is specially designed to work with Microsoft .NET platform. 2) Explain about the rules for naming classes in C#? These are the rules for naming classes in c sharp. Must begin with a letter. This letter may be followed by a sequence of letters, digits (0-9), or _. The first character in a class name cannot be a digit. Must not contain any embedded space or symbol like ? - + ! @ # % & * ( ) { } [ ] , : ; \ and/. However an underscore _ can be used wherever a space is required. Must not use a keyword for a class name. 3) What are the rules to be followed while naming variables in C#. The following rules are used for naming variables in C#. * Must begin with a letter or an underscore _ which may be followed by a sequence of letters, digits (0-9), or _. The first character in a variable name cannot be a digit. * Must not contain any embedded space or symbol like ? - + ! @ # % & * ( ) { } [ ] , : ; \ and/. However an underscore _ can be used wherever a space is required. Must be unique Can have any number of characters Keywords cannot be used as variable names. 4) What are the different types of Data? There are two different types of data supported by C#. They are 1) Value types: -They directly contain data. When you declare an int variable, the system allocates memory to store the value. 2) Reference type: -The reference types do not maintain data but they contain a reference to the variables, which are stored in memory. This means that if the value in the memory location is modified by one of the variables, the other variables automatically reflect the changes value 5) Explain about member functions? A function is a set of statements that perform a specific task in response to a message. The

functions of a class are called member functions in Csharp. Member functions are declared inside the class. The function declaration introduces the function in the class and the function definition contains the function code. 6) Explain about comment entry? Comments are a part of the program and are used to explain the code. Compilers ignore comment entries. If a comment entry spans more than one line, it has to be enclosed within /* and */. The symbol // treats the rest of code within the same line as a comment. 7) What are operators? Applications use operators to process the data entered by a user. Operators like + and are used to process variables and return a value. An operator is a set of one or more characters that is used for computations or comparisons. Operators can transform one or more data values, called operands into a new data value. 8) Explain about the break statement? A break statement is used to exit the switch statement. This prevents the execution of the remaining case structures by ending the execution of the switch case construct. Each break statement terminates the enclosing switch statement and the flow of control. If none of the cases match the default case is invoked. 9) Define encapsulation? Encapsulation literally means to enclose in or as if in a capsule. Encapsulation is defined as the process of enclosing one or more items within a physical or logical package. It involves preventing access to nonessential details. 10) Define access specifier with reference to class? An access specifier defines the scope of a class member. A class member refers to the variables and functions in a class. A program can have one or more classes. You may want some members of a class to be accessible to other classes. But, you may not want some other members of the class to be accessible outside the class. 11) Describe about private access specifier? The private access specifier allows a class to hide its member variables and member functions from other class objects and functions. Therefore, the private member of a class is not visible outside a class. If a member is declared private, only the functions of that class can access the member. Even the instance of the class cannot access its members 12) Explain about protected internal access specifier? This specifier allows a class to hide its member variables and member functions to be accessed from other class objects and functions, except the child class, within the application. The protected internal access specifier becomes important while implementing inheritance. 13) Define parameter by value? Pass by value is the default mechanism for passing parameters to a method. The simplest

definition of a value parameter is a data type name followed by a variable name. When a method is called, a new storage location is created for each value parameter. The values of the corresponding expressions are copied into them. The expression supplied for each value parameter must be similar to the declaration of the value parameter. 14) State the methods through which parameters can be passed? Parameters can be passed by using any one of the following mechanism. Value: -They are sometimes called in or out parameters; therefore, the data can be transferred into the method but cannot be transferred out. Reference: -Are sometimes called in or out parameters, therefore, the data can be transferred into the method and out again. Output: -Are sometimes called out parameters, data can be transferred out of the method. 15) Explain about reference parameter? A reference parameter is a reference to a memory location of a data member. Unlike a value parameter, a reference parameter does not create a new storage location. Instead a reference parameter represents the same location in memory as the variable that is supplied in the method call. 16) How do you use a structure? A structure is a value type data type. When you want a single variable to hold related data of various data types, you can create a structure. To create a structure you use the struct keyword. 17) What is an enumerator? Enumeration is a value data type, which means that enumeration contains its own values and cannot inherit or pass inheritance. Enumerator allows you to assign symbolic names or integral constants.

1. How many types of JIT compilers are available? There are Two types of JIT compilers. standard JIT compiler. EconoJIT compiler.

2.What are the different types of assemblies name them? Private Public/Shared

Satellite assembly

3.What is GAC? What are the steps to be taken to pick up the latest version from GAC? This Global Assembly Cache(GAC) stores .NET assemblies to be shared by several applications on that computer.publisher policy file is the configuration file to redirect to different version 1. Create the publisher Policy assembly using the assembly linker 2. Add the publisher policy assembly to the GAC using GACutil tool Gacutil /i 3. During runtime CLR is looking into the publisher policy file and redirect the application to bind with new version assembly as specified inside the publisher policy.

4.How do we use different versions of private assemblies in same application without re-build? In Asseblyinfo file need specify assembly version. assembly: AssemblyVersion

5.Different methods of using a legacy COM component in .NET framework? 1. TLBIMP to create an Assembly from a COM component 2. Reference a COM component directly from .NET Editor

6.How do you implement SSL? 1. create certificate request [ =>Right click on the website (VD) =>Click Directory Security Tab and click Server Certificate => Type name of certificate , Organization name , server name location info, => Type the path need to save certificate information Submit certificate request.

7.What is ref parameter? What is out parameter? Ref Parameter: Used to pass a parameter as a reference so that the function called will set the value. This could be used to return more than 1 value by a function. e.g. public int AddMuliply( int a , int b, ref int c) { c = a*b; return ( a+b); } The above function, returns the addition of two numbers as well as computes the multiplication result and passes to the calling function. Out Parameter: Used to pass values from the aspx Code-behind to the aspx page. The difference is that for a ref parameter, you have to assign a value before you call the function, while for OUT parameter, you dont have to assign a value, the calling function assumes that the called function would assign some value.

A ref parameter must first be initialized before being passed from the calling function to the called function. but a out parameter need not be initialized, we can pass it directly when we pass a parameter as ref to a method, the method refers to the same variable and changes made will affect the actual variable. even the variable passed as out parameter is same as ref parameter, but implementation in c# is different, Arguement passed as ref parameter must be initialized before it is passed to the method. But in case of out parameter it is not necessary. But after a call to a method as out parameter it is necessary to initialize. When to use out and ref parameter, out parameter is used when we want to return more than one value from a method. Ref parameter can be used as both input and o/p parameter out parameter can be used as only output parameter

8.What is boxing? What is the benefits and disadvantages?

Boxing is converting a value-type to reference type. An example is converting an integer value to an object value.

Ex: int intValue = 10; object obj = (object)intValue;

This is used if you want to pass variables of object types to certain functions or methods you have created. Commonly used in events for example (Object sender...).

9.Why multiple Inheritance is not possible in C#? Multple inheritance is coneceptually wrong. It shouldn't be allowed in any language. Inheritance is the strongest relationship that can be expressed in OO languages. It's used to express IS-A relationship. Aggregation is used to express IS CONSTRUCTED IN TERMS OF. If you're using multiple inheritance in C++ then you're design is wrong and you probably want to use aggregation. On the other hand it's plausible to want to use multiple interfaces. For instance you might have a class wheel and a class engine. You could say that your class car inherits from wheel and from engine but that's wrong. In fact car aggregates wheel and engine because it is built in terms of those classes. If wheel is an interface and engine is an interface then car must inherit both of these interfaces since it must implement the functionaity of wheel and engine .On this basis we can see that multiple inheritance for classes should not be allowed because it promotes mis-use of the strong IS-A relationship. C# enforces the correct concepts whilst C++ allows mis-use. multiple interface inheritance is permissible and C# allows this. It's all to do with properly understanding OO concepts.

Absolute Multiple Inheritance is not possible in c# but partially it supports multiple inheritance by the use of Interfaces. As interfaces force a class to implement same type of behaviour (as defined in interface) which classes implements that interface

What is the top .NET class that everything is derived from? System.Objects

What is an abstract class? The abstract modifier can be used with classes, methods, properties, indexers, and events. Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes.

Abstract classes have the following features: An abstract class cannot be instantiated. An abstract class may contain abstract methods and accessors. It is not possible to modify an abstract class with the sealed modifier, which means that the class cannot be inherited. A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors. Use the abstract modifier in a method or property declaration to indicate that the method or property does not contain implementation.

Abstract methods have the following features: An abstract method is implicitly a virtual method. Abstract method declarations are only permitted in abstract classes. Because an abstract method declaration provides no actual implementation, there is no method body; the method declaration simply ends with a semicolon and there are no braces ({ }) following the signature. For example: public abstract void MyMethod(); ________________________________________ abstract class is a prototype of a class. it is used to provide partial class implementation. abstract class contain abstract method which can be implemented by derived class. some rules for abstract class are following-: 1) an object of an abstract class can never be created.

2)you can not declare an abstract method outside the abstract class. 3)can not be declared sealed.

WHAT IS THE ADVANTAGE OF SERIALIZATION? Serialization is the process of maintaing object in the form stream. it is useful in case of remoting. Serialization is the process of converting object into byte stream which is useful to transport object(i.e remoting),persisting object(i.e files,database) SERIALIZATION IS PROCESS OF LOADING THE OBJECT STATE IN THE FORM OF BYTE STREAMS IN DATABASE/FILE SYATEM.

Can we inherit the java class in C# class,how? Java Programming language is not supported with .Net Framework hence you cannot inherit javaclass in C# class.Also Java has JavaByte code after compiling similar to MSIL which is similar but cannot inherit due to framework support.

Are C# destructors the same as C++ destructors? No. They look the same but they are very different. The C# destructor syntax (with the familiar ~ character) is just syntactic sugar for an override of the System.Object Finalize method. This Finalize method is called by the garbage collector when it determines that an object is no longer referenced, before it frees the memory associated with the object. So far this sounds like a C++ destructor. The difference is that the garbage collector makes no guarantees about when this procedure happens. Indeed, the algorithm employed by the CLR garbage collector means that it may be a long time after the application has finished with the object. This lack of certainty is often termed non-deterministic finalization, and it means that C# destructors are not suitable for releasing scarce resources such as database connections, file handles etc. To achieve deterministic destruction, a class must offer a method to be used for the purpose. The standard approach is for the class to implement the IDisposable interface. The user of the object must call the Dispose() method when it has finished with the object. C# offers the using construct to make this easier.

What is wrapper class? is it available in c#? Wrapper Classes are the classes that wrap up the primitive values in to a class that offer utility method to access it . For eg you can store list of int values in a vector class and access the class. Also the methods are static and hence you can use them without creating an instance . The values are immutable . wrapper class are those class in which we can not define and call all predefined function .it is possible in java not C#.

Which tool is used to browse the classes, structs, interfaces etc. in the BCL? wincv as in Windows Class View

How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization? The using() pattern is useful because it ensures that Dispose() will always be called when a disposable object (defined as one that implements IDisposable, and thus the Dispose() method) goes out of scope, even if it does so by an exception being thrown, and thus that resources are always released.

What happens when a C# project has more than 1 Main methods f the project is compiled using /main switch with the compiler then the project compiles successfully.

For example: class A { public static void Main(string[] args) { Console.WriteLine("Main in class A"); } }

class B { public static void Main(string[] args) { Console.WriteLine("Main in class B"); } }

Now compile with the /main switch with the C# compiler like csc MultipleMain.cs /main:A

This will compile without error and while executing it will show Main in class A

Attempting to compile an application consisting of multiple classes with defined Main methods and not specifying the /main switch will result in a compiler error. How do you refer parent classes in C#? A) Super B) This C) Base This keyword is used for reffering current object and Base keyword is used for referring parrent class. so ans. is C. Super: Super is used to Refer the Base Class in JAVA This: This is used to Refer the Current or Child Class in C# Base: Base is used to Refer The Parent or Base Class

What is object pooling Defination: A performance optimization based on using collections of pre-allocated resources, such as objects or database connections With the advent of the .NET platform, writing code that pools objects and threads has become a simple task. By using the Threading and Collections namespaces, you can create robust object pooling applications. This could also be done by implementing COM+ interop interfaces into your code.

Which method is actually called ultimately when Console.WriteLine( ) is invoked?

A) Append( ) B) AppendFormat( ) C) Tostring( ) Ans: B, AppendFormat() method is called.

What is an Assembly? An assembly is a file that is automatically generated by the compiler upon successful compilation of every .NET application. It can be either a Dynamic Link Library or an executable file. It is generated only once for an application and upon each subsequent compilation the assembly gets updated. The entire process will run in the background of your application; there is no need for you to learn deeply about assemblies. However, a basic knowledge about this topic will help you to understand the architecture behind a .NET application. An assembly is used by the .NET CLR (Common Language Runtime) as the smallest unit for: deployment; version control; security; type grouping and code reuse. Assemblies consists of a manifest and one or more modules and/or files like HTML, XML, images, video clips,...

An assembly can be thought of as a logical DLL and must contain a single manifest and may optionally contain type meta data, MSIL (Microsoft Intermediate Language) and resources.

Assemblies come in 2 flavors: application private and shared. Application private assemblies are used by one application only. This is the default style of assembly. Such assemblies must reside in the application folder.

Shared assemblies are meant to be used by more than one application. They must have a globally unique name and must be defined in the GAC (Global Assembly Cache). To learn more about viewing the GAC Basically there are two kind of assemblies when it comes to deployment. Private Assemblies Shared Assemblies

Private assemblies are the ones which are in your application folder itself. They can be easily

and uniquely identified by their name. These type of assemblies can be deployed simply by copying them to the bin folder of your application.

Shared Assemblies are those which can be shared by multiple applications on the machine. For this we have to place the Shared assembly in the GAC.

Now since we can install any application or assembly created by any company, that is we install assemblies from oracle, microsoft and similarly from many other companies.

There is always a possiblity that they may use the same assembly name as your assembly name. If such type of assemblies are placed in the GAC then we cannot uniquely identify a particular assembly.But if we give a strong name to the assmebly then it is like a unique identifier for the assembly.It is Globally unique.

Strong name consists of 1. Name of the assembly 2. Public key token 3. optionally any resources 4. Version Number

So basically to uniquely identify a particular assembly from the GAC we have to give it a strong name. Its that simple. The Shared assembly can be deployed in to GAC by using the GACUTIL tool with the -i switch gacutil -i assemblyname or simply copying it to the assembly folder in the windows directory (XP) or WINNT directory(others) Also there are Satellite Assemblies which contian only resources like strings, images etc. Also there are dynamic assemblies which are generated on the fly dynamically.

What does the modifier protected internal in C# mean? The Protected Internal can be accessed by Members of the Assembly or the inheriting class, and of course, within the class itself.

In VB.NET, the equivalent of protected internal is protected friend. The access of this modifier is limited to the current assembly or the types derived from the defining class in the current assembly. To know more on different types of access specifiers Can multiple data types be stored in System.Array? So whats an array all about? An array is a collection of items of the same type, that is grouped together and encompassed within an array object. The array object, or the System.Array object to be precise, is derived from the System.Object class. It is thus, stored in the form of a heap in the memory.

An array may be of single dimensional, multi-dimensional or jagged (a jagged array means an array within an array).

A group of items when assigned values within braces implicitly derive from System.Array class. See example below written in C#... int[] testIntArray = new int[4] { 2, 3, 4, 5 }; Object[] testObjArray = new Object[5] { 32, 22, 23, 69, 75 }; Ideally an array should contain a single data type. But still in case there is a requirement to place data of different data types in a specific array, then in such a scenario, the data elements should be declared as an object type. When this is done, then each element may point ultimately to a different data type. See code example below written in VB.NET... Dim allTypes As Object() = New Object() {}

'In this kind of scenario, the performance may tend to slow down, as data conversions may take place. 'In case a value type is converted to reference type, then boxing and unboxing occurs 'To know more on Value Types & Reference Types, Click Here

Dim studentTable(2) As Object studendTable(0) = "Vishal Khanna" studentTable(1) = 28 studentTable(2) = #9/1/1978#

'To get these values of these varying datatypes, their values are converted to their original data type

Dim myAge As Integer = CInt(studentTable(1)) Dim myBirthDay as Date = CDate(studentTable(2))

How to sort array elements in descending order in C#? Elements of an array may not be sorted by default. To sort them in descending order, the Sort() method is first called. Next, to descend the order, call the Reverse() method

Whats the use of "throw" keyword in C#? The throw keyword is used to throw an exception programatically in C#. In .NET, there is an inbuilt technique to manage & throw exceptions. In C#, there are 3 keyword, that are used to implement the Exception Handling. These are the try, catch and finally keywords. In case an exception has to be implicitly thrown, then the throw keyword is used. See code example below, for throwing an exception programatically... class SomeClass { public static void Main() { try { throw new DivideByZeroException("Invalid Division Occured"); } catch(DivideByZeroException e)

{ Console.WriteLine("Exception - Divide by Zero" ); } } }

Can we put multiple catch blocks in a single try statement in C#? Yes. Multiple catch blocks may be put in a try block. See code example below, to see multiple catch blocks being used in C#. class ClassA { public static void Main() { int y = 0; try { val = 100/y; Console.WriteLine("Line not executed"); } catch(DivideByZeroException ex) { Console.WriteLine("DivideByZeroException" ); } catch(Exception ex) { Console.WritLine("Some Exception" ); } finally { Console.WriteLine("This Finally Line gets executed always"); }

Console.WriteLine("Result is {0}",val); } }

How to achieve polymorphism in C#? In C#, polymorphism may be achieved by overloading a function, overloading an operator, changing the order of types, changing the types using the same name for the member in context. To see some code examples of polymorphism, Click Here.

What is polymorphism? Polymorphism means allowing a single definition to be used with different types of data (specifically, different classes of objects). For example, a polymorphic function definition can replace several type-specific ones, and a single polymorphic operator can act in expressions of various types. Many programming languages implement some forms of polymorphism.

The concept of polymorphism applies to data types in addition to functions. A function that can evaluate to and be applied to values of different types is known as a polymorphic function. A data type that contains elements of different types is known as a polymorphic data type.

Polymorphism may be achieved by overloading a function, overloading an operator, changing the order of types, changing the types using the same name for the member in context. Example: Public Class Calc { public void fnMultiply(int x, int y) { return x * y; } public void fnMultiply(int x, int y, int z) { return x * y * z; } } ... ...

Calc obj; int Result; Result = obj.fnMultiply(2,3,4); // The second fnMultiply would be called Result = obj.fnMultiply(3,4); // The first fnMultiply would be called //Here, the call depends on the number of parameters passed, polymorphism is achieved using overloading

How to add a ReadOnly property in C#? Property - A property is an entity that describes the features of an object. A property is a piece of data contained within a class that has an exposed interface for reading/writing. Looking at that definition, you might think you could declare a public variable in a class and call it a property. While this assumption is somewhat valid, the true technical term for a public variable in a class is a field. The key difference between a field and a property is in the inclusion of an interface. We make use of Get and Set keywords while working with properties. We prefix the variables used within this code block with an underscore. Value is a keyword, that holds the value which is being retrieved or set. See code below to set a property as ReadOnly. If a property does not have a set accessor, it becomes a ReadOnly property.

public class ClassA { private int length = 0; public ClassA(int propVal) { length = propVal; } public int length { get { return length; }

} }

How to prevent a class from being inherited? Sealed in C#? In order to prevent a class in C# from being inherited, the sealed keyword is used. Thus a sealed class may not serve as a base class of any other class. It is also obvious that a sealed class cannot be an abstract class. Code below... sealed class ClassA { public int x; public int y; } No class can inherit from ClassA defined above. Instances of ClassA may be created and its members may then be accessed, but nothing like the code below is possible... class DerivedClass: ClassA {} // Error

Can we inherit multiple interfaces in C#? Yes. Multiple interfaces may be inherited in C#.

Note that when a class and multiple interfaces are to be inherited, then the class name should be written first, followed by the names of the interfaces. See code example below, on how to inherit multiple interfaces in C#. class someclass : parentclass, IInterface1, IInterface2 { //...Some code in C# }

What are the different ways of overloading methods in C#?

What is function overloading in C#?

Before knowing the different methods of overloading in C#, lets first clear out what exactly overloading is. Overloading is the OOPs concept of using a method or a class in different styles by modifying the signature of the parameters in it. To know more on overloading, Click Here.

In order to achieve overloading, there may be several techniques applied. There are different types of overloading like Operator Overloading, Function Overloading etc.

Function overloading may be achieved by changing the order of parameters in a function, by changing the types passed in the function, and also by changing the number of parameters passed in a function. See code sample below to see types of overloading. //Define a method below public void fnProcess(int x, double y) { ...... } //change the order of parameters public void fnProcess(double x, int y) { //.......Some code in C# } //Similarly, we may change the number of parameters in fnProcess //and alter its behaviour

How to call a specific base constructor in C#?

What is a Constructor? - It is a method that gets invoked when an instance of a class is created. In case a class has plenty of constructors, i.e. there are plenty of overloaded constructors, in such a scenario, it is still possible to invoke a specific base constructor. But there is a special way, as explicit calls to a base constructor is not possible in C#. See code below: public class dotnetClass { public dotnetClass()

{ // The constructor method here } // Write the class members here }

//Sample code below shows how to overload a constructor public class dotnetClass { public dotnetClass() { // This constructor is without a parameter // Constructor #1 }

public dotnetClass(string name) { // This constructor has 1 parameter. // Constructor #2

} } This constructor gets executed when an object of this class is instantiated. This is possible in C#. Calling a specific constructor will depend on how many parameters, and what parameters match a specific constructor. Note that a compile time error may get generated when 2 constructors of the same signature are created.

We may make use of the this keyword and invoke a constructor. See code example below. this("some dotnet string"); //This will call Constructor #2 above

What is the use of the base keyword. Suppose we have a derived class named dotnetderivedclass. If this derived class is to invoke the constructor of a base class, we make use of the base keyword. See code example below on how to use a base keyword to invoke the base class constructor. public class dotnetClass { public dotnetClass() { // The 1st base class constructor defined here }

public dotnetClass(string Name) { // The 2nd base class constructor defined here } }

public class dotnetderivedclass : dotnetClass // A class is being inherited out here { public dotnetderivedclass() { // dotnetderivedclass 1st constructor defined here }

public dotnetderivedclass(string name):base(name) { // dotnetderivedclass 2nd constructor defined here } }

Note that we have used the base keyword in the sample code above. The sequence of execution of the constructors will be as follows: public dotnetClass() method -> public dotnetderivedclass() method

The above sequence triggers when there is no initializer to the base class, and thus it triggers the parameterless base class constructor. The other base class constructor may also get invoked when we pass a parameter while defining it.

What is a static constructor?

Static Constructor - It is a special type of constructor, introduced with C#. It gets called before the creation of the first object of a class(probably at the time of loading an assembly). See example below. Example: public class SomeClass() { static SomeClass() { //Static members may be accessed from here //Code for Initialization } } While creating a static constructor, a few things need to be kept in mind: * There is no access modifier require to define a static constructor * There may be only one static constructor in a class * The static constructor may not have any parameters * This constructor may only access the static members of the class * We may create more than one static constructor for a class

Can a class be created without a constructor? No. In case we dont define the constructor, the class will access the no-argument constructor

from its base class. The compiler will make this happen during compilation.

What are generics in C#? Generics in C# is a new innovative feature through which classes and methods in C# may be designed in such a way that the rules of a type are not followed until it is declared. The generics feature in C# has been introduced with version 2.0 of the .NET Framework. Using generics, a class template may be declared that may follow any type as required at runtime. The class behavior is later governed by the type that we pass to the class. Once the type is passed, the class behaves depending on the type passed to this generic class.

What is the use of the main() function in C#? Every executable C# application must contain a class defining a Main() method that signifies the entry point of the application. Note that the Main() method is of the access type public by nature. Moreover, it is also static. See example below: using System; class Question { public static int Main(string[] args) { Console.Writeline("Another Question"); Console.Readline(); return 0; } }

A public member is accessible from other types. The main() method is set as static so that it may be invoked at class level itself, without the need of creating an instance of it. The single parameter is an array of strings. that may contain any number of incoming command line arguments.

Can we set the specifier of the main() method in C# as private? Yes. When the access specifier is set as private for the Main() method, then other assemblies may not invoke this class' Main() method as the starting point of the application. The startup scope gets limited to the class in context itself. See code below: private static void Main() { //This code isn't invoked automatically by other assemblies }

Can we set different types of parameters & return-types in main() method"? Yes. The Main() method may easily be played around with by developers by passing different parameters and setting different return types. See the code below, that demonstrates different ways the Main() method may be implemented: (1) public static void Main(string[] args) { //NO return type, the argument is an array of strings }

(2) public static int Main(string[] args) { //Return type is int, argument is an array of strings }

(3) public static int Main() { //Return type is int, NO arguments }

(4) public static void Main() { //Return type is void, NO arguments }

What is the use of GetCommandLineArgs() method? The GetCommandLineArgs() method is used to access the command line arguments. The return value of this method is an array of strings. It is a method of the System.Environment class. See the code example below: public static int Main(string[] args) { string[] strArgs = System.Environment.GetCommandLineArgs(); Console.WriteLine("Arguments {0}", strArgs[0]); }

What is the use of System.Environment class? The class System.Environment is used to retrieve information about the operating system. Some of the static members of this class are as follows: 1) Environment.OSVersion - Gets the version of the operating system 2) Environment.GetLogicalDrives() - method that returns the drives 3) Environment.Version - returns the .NET version running the application 4) Environment.MachineName - Gets name of the current machine 5) Environment.Newline - Gets the newline symbol for the environment 6) Environment.ProcessorCount - returns number of processors on current machine 7) Environment.SystemDirectory - returns complete path to the System Directory 8) Environment.UserName - returns name of the entity that invoked the application

Why is the new keyword used for instantiating an object in .NET? The new keyword instructs the .NET compiler to instantiate a new object, with appropriate number of bytes (depending on the type) for the object and gather required memory from the

managed heap.

What are the default values for bool, int, double, string, char, reference-type variables? When the objects of the following types are declared, then they have a default value during declaration. The following table shows the default value for each type: Type Default Value bool false int 0 double 0 string null char '\0' Reference Type null

How to declare a constant variable in C#? What is the use of the const keyword? If a variable needs to have a fixed value, that may not be changed across the application's life, then it may be declared with the const keyword. The value assigned to a constant variable (using the const keyword) must be known at the time of compilation

In C#, can we create an object of reference type using const keyword? No. A constant member may not be created of an object that is of reference type, because its value is decided dynamically at runtime.

What is the difference between const and readonly in C#? When using the const keyword to set a constant variable, the value needs to be set at compile time. The const keyword may not be used with an object of reference type. In case a reference type needs to be assigned a non-changeable value, it may be set as readonly

What are the different parameter modifiers available in C#?

What is a parameter modifier?

Parameter modifiers in C# are entities that controls the behaviour of the arguments passed in a method. Following are the different parameter modifiers in C#: 1) None - if there is NO parameter modifier with an argument, it is passed by value, where the method recieves a copy of the original data. 2) out - argument is passed by reference. The argument marked with "out" modifier needs to be assigned a value within this function, otherwise a compiler error is returned. public void multiply(int a, int b, out int prod) { prod = a * b; } Here, note that prod is assigned a value. If not done so, then a compile time error is returned. 3) params- This modifier gives the permission to set a variable number of identical datatype arguments. Note that a method may have only one "params" modifier. The params modifier needs to be in the last argument. static int totalruns(params int[] runs) { int score = 0; for(int x=0; x &nsbp;score+=runs[x]; return score; } Further, from the calling function, we may pass the scores of each batsman as below... score = totalruns(12,36,0,5,83,25,26);

4) ref - The argument is given a value by the caller, where data is passed by reference. This value may optionally be reset in the called method. Note that even if NO value is set in the called method for the ref attribute, no compiler error is raised.

What is the difference between out and ref in C#? 1) out parameters return compiler error if they are not assigned a value in the method. Not such

with ref parameters.

2) out parameters need not be initialized before passing to the method, whereas ref parameters need to have an initial value before they are passed to a method.

What is delay signing? Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.

Is there an equivalent of exit() for quitting a C# .NET application? Yes, you can use System.Environment.Exit(int exitCode) to exit the application or Application.Exit() if it's a Windows Forms app. Can you prevent your class from being inherited and becoming a base class for some other classes? Yes, that is what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It is the same concept as final class in Java.

If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor? Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

I was trying to use an "out int" parameter in one of my functions. How should I declare the variable that I am passing to it?

You should declare the variable as an int, but when you pass it in you must specify it as 'out', like the following: int i; foo(out i); where foo is declared as follows: [return-type] foo(out int o) { }

How do I make a DLL in C#? You need to use the /target:library compiler option.

Is XML case-sensitive? Yes, so and are different elements.

How do I simulate optional parameters to COM calls? You must use the Missing class and pass Missing.Value (in System.Reflection) for any values that have optional parameters.

Will finally block get executed if the exception had not occurred? Yes.

What is the C# equivalent of C++ catch (), which was a catch-all statement for any possible exception? Does C# support try-catch-finally blocks? Yes. Try-catch-finally blocks are supported by the C# compiler. Here's an example of a trycatch-finally block: using System; public class TryTest { static void Main() { try {

Console.WriteLine("In Try block"); throw new ArgumentException(); } catch(ArgumentException n1) { Console.WriteLine("Catch Block"); } finally { Console.WriteLine("Finally Block"); } } } Output: In Try Block Catch Block Finally Block

If I return out of a try/finally in C#, does the code in the finally-clause run? Yes. The code in the finally always runs. If you return out of the try block, or even if you do a "goto" out of the try, the finally block always runs, as shown in the following example: using System; class main { public static void Main() { try { Console.WriteLine("In Try block"); return; }

finally { Console.WriteLine("In Finally block"); } } }

Both "In Try block" and "In Finally block" will be displayed. Whether the return is in the try block or after the try-finally block, performance is not affected either way. The compiler treats it as if the return were outside the try block anyway. If it's a return without an expression (as it is above), the IL emitted is identical whether the return is inside or outside of the try. If the return has an expression, there's an extra store/load of the value of the expression (since it has to be computed within the try block).

Is there a way to force garbage collection? Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.GC.Collect() doesn't seem to be doing it for you, you can force finalizers to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers().

Is there regular expression (regex) support available to C# developers? Yes. The .NET class libraries provide support for regular expressions. Look at the documentation for the System.Text.RegularExpressions namespace.

Does C# support properties of array types? Yes. Here's a simple example: using System; class Class1 { private string[] MyField; public string[] MyProperty {

get { return MyField; } set { MyField = value; } } } class MainClass { public static int Main(string[] args) { Class1 c = new Class1(); string[] arr = new string[] {"apple", "banana"}; c.MyProperty = arr; Console.WriteLine(c.MyProperty[0]); // "apple" return 0; } }

What connections does Microsoft SQL Server support? Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords)

When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)? When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.

Why would you use untrusted verification? Web Services might use it, as well as non-Windows applications.

How is method overriding different from overloading? When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

What is the implicit name of the parameter that gets passed into the class set method? Value, and its datatype depends on whatever variable we are changing.

How do I register my code for use by classic COM clients? Use the regasm.exe utility to generate a type library (if needed) and the necessary entries in the Windows Registry to make a class available to classic COM clients. Once a class is registered in the Windows Registry with regasm.exe, a COM client can use the class as though it were a COM class

Q1. What is WPF? WPF stands for Windows Presentation Foundation. It is an application programming Interface for developing rich UI on Windows. WPF is introduced in .NET 3.0. By the use of WPF we can create two and three dimensional graphics,animations etc.

Q2. What is XAML and how it is related to WPF? XAML is a new mark up language which is used for defining UI elements and its relationships with other UI elements. The XAML is introduced by WPF in .NET 3.0 WPF uses XAML for UI design.

Q3. Does XAML file compiled or Parsed? By default XAML files are compiled ,But we do have options to let it be parsed.

Q4. What is the root namespace used for Animations and 3D rendering in WPF? System.Windows.Media namespace.

Q5. What are the names of main asseblies used by WPF?

a)WindowsBase b)PresentationCore c)PresentationFoundation

Q6. What operating systems support WPF? Following are the operating systems that support WPF a)Windows7 b)Windows Vista c)Windows XP Service Pack 2 or later

Q7. Describe the types of documents supported by WPF? There are two kinds of document supported by WPF a)Flow format:Flow format document adjusts as per screen size and resolution b)Fixed Format:Fixed Format document does not adjust as per screen size and resolution

Q8. What namespaces are needed to host a WPF control in Windows form application? The following namespaces needs to be referenced : a)PresentationCore.dll b)PresentationFramework.dll c)UIAutomationProvider.dll d)UIAutomationTypes.dll e)WindowsBase.dll

Q9. What is Dependency Property In WPF? Windows Presentation Foundation (WPF) has a set of services that is used to extend the functionality of a common language runtime property. These services are referred as the WPF property system. A property that is backed by the WPF property system is known as a dependency property

Q10.What is routed event in WPF?

A WPF user interface is constructed in a layered approach, where one visual element can have zero or more child elements. so we can visualise the elements tree for the full page. Routed events are a new feature provided by WPF which allows events to travel down the elements tree to the target element, or bubble up the elements tree to the root element. When an event is raised, it "travels" up or down the elements tree invoking handlers for that event on any element subscribed to that event it encounters en route.This tree traversal does not cover the entire elements tree, only the ancestral element chain between the root element and the element which is the target of the event. Interview Questions and Answer on .Net,C#,ASP.NET,SQL Server
y

All .NET training videos and explanation are not just theory and one liners. They are in depth videos with source code and explanation and finally taking out the actual meat which you need to speak before the interviewer to impress him.

We do not just provide videos and leave the developers on their own.Online support via live meeting from Microsoft MVP's takes this product to a greater height.

We understand no one can see 500 videos at one go. We organize regularC# training on various topics so that your learning curve is reduced to a great extent.

Around 500 videos covering right from .NET, CSharp Interview Questions and Answers. You are either a fresher /senior architect /project manager this solution is for every level.

y y

Full DVD delivered to your doorsteps( only for USA , India and Canada). Mock interviews, Mock interviews , Mock interviews and Mock interviews makes this solution and perfect package for your job search. These mock interviews are conducted by our specialist to evaluate how much you are prepared and ready.

y y

Superb one liner interview answer cheat sheet to make you revise in a day. Videos are not just theory and talks , its Step by Step demonstration with actual code and fundamentals.

Money back if you are not satisfied with our videos and support. Summary of Topics Covered in .Net Training

We understand that working on a project is one thing but clearing interviews needs a change of mind set and this solution is especially meant for the same. From the same aspect we have divided our interview videos are divided in 5 essential categories :y y

Basic .NET, ASP.NET, OOPS and SQL Server. Interview questions and answers New technologies WCF, WPF, Silverlight , LINQ, Azure, EF and 4.0. Interview questions and answers

Design pattern, UML, Architecture, Estimation, Project management, VSTS. Interview questions and answers

y y

Complete Invoicing project end to end. Interview questions and answers Server products (Sharepoint 2007 questions and answer videos). Interview questions and answers

Best practices and SQL performance tuning. Interview questions and answers Details of the above .Net Training Topics Below is our detail video list of the above main .Net Training topics. All .net training videos go in-depth with source code and then explaining you the one liner which you need to speak in the interview.

Basic .NET, ASP.NET, OOPS and SQL Server Interview questions and answers.
y y y y y y y y y y

What is IL code, CLR, CTS, GAC & GC? How can we do Assembly versioning? can you explain how ASP.NET application life cycle and page life cycle events fire? What is the problem with Functional Programming? Can you define OOP and the 4 principles of OOP? What are Classes and Objects? What is Inheritance? What is Polymorphism, overloading, overriding and virtual? Can you explain encapsulation and abstraction? What is an abstract class?

y y y y y y y y y y y y

Define Interface & What is the diff. between abstract & interface? What problem does Delegate Solve ? What is a Multicast delegate ? What are events and what's the difference between delegates and events? How can we make Asynchronous method calls using delegates ? What is a stack, Heap, Value types and Reference types ? What is boxing and unboxing ? Can you explain ASP.NET application and Page life cycle ? What is Authentication, Authorization, Principal & Identity objects? How can we do Inproc and outProc session management ? How can we windows , forms and passport authentication and authorization in ASP.NET ? In a parent child relationship which constructor fires first ? MVC ASP.NET Q & A series

y y y y y

How to create a simple "Hello World" using ASP.NET MVC template? - Lab 1 How to pass data from controller to views? - Lab 2 Can we see a simple sample of model using MVC template? - Lab 3 How can we create simple input screens using MVC template? - Lab 4 How can we create MVC views faster and make them strong typed by using HTML helper? Lab 5

y y y y

Can we see how easy it is do unit testing for MVC application? - Lab 6 What is MVC routing? - Lab 7 How can we set default values & validate MVC routes? - Lab 8 How we can define actions & navigate from one page to other page? - Lab 9 WCF, WPF, Silverlight, LINQ, Azure and EF 4.0 interview question and answers

y y y y

What is SOA, Services and Messages ? What is the difference between Service and Component? What are basic steps to create a WCF service ? What are endpoints, address, contracts and bindings?

y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y

What are various ways of hosting WCF service? What is the difference of hosting a WCF service on IIS and Self hosting? What is the difference between BasicHttpBinding and WsHttpBinding? How can we do debugging and tracing in WCF? Can you explain transactions in WCF (theory)? How can we self host WCF service ? What are the different ways of implementing WCF Security? How can we implement SSL security on WCF(Transport Security)? How can we implement transport security plus message security in WCF ? How can we do WCF instancing ? How Can we do WCF Concurency and throttling? Can you explain the architecture of Silverlight ? What are the basic things needed to make a silverlight application ? How can we do transformations in SilverLight ? Can you explain animation fundamentals in SilverLight? What are the different layout methodologies in SilverLight? Can you explain one way , two way and one time bindings? How can we consume WCF service in SilverLight? How can we connect databases using SilverLight? What is LINQ and can you explain same with example? Can you explain a simple example of LINQ to SQL? How can we define relationships using LINQ to SQL? How can we optimize LINQ relationships queries using DataLoadOptions? Can we see a simple example of how we can do CRUD using LINQ to SQL? How can we call a stored procedure using LINQ? What is the need of WPF when we had GDI, GDI+ and DirectX? Can you explain how we can make a simple WPF application? Can you explain the three rendering modes i.e. Tier 0 , Tier 1 and Tier 2? Can you explain the Architecture of WPF? What is Azure? Can you explain Azure Costing?

y y y y y y y y y

Can we see a simple Azure sample program? What are the different steps to create a simple Worker application? Can we understand Blobs in steps, Tables & Queues ? Can we see a simple example for Azure tables? What is Package and One click deploy(Deployment Part - 1) ? What is Web.config transformation (Deployment Part-2)? What is MEF and how can we implement the same? How is MEF different from DIIOC? Can you show us a simple implementation of MEF in Silverlight ?

ASP .NET

1) Explain about ASP.NET? Microsoft introduced the .Net framework with the intention of bridging the gap in interoperability between applications. This framework aims at integrating various programming languages and services. The .NET offers a complete suite for developing and deploying applications. 2) State the various features present in .NET? It is designed to make significant improvements in code reuse, code specialization, resource management, Multilanguage development, security, deployment and administration. There are lots more features included in Microsoft .net which can be realized to a maximum potential with the language support. 3) Explain about .Net products? Microsoft has already introduced visual studio.NET, which is a tool for developing .NET applications by using programming languages such as Visual Basic, Visual C#, and Visual C++. These products aim at allowing developers to create applications, which are capable of interacting seamlessly with each other. 4) Which platform does Microsoft .NET uses for exchanging data between applications? .Net products use eXtensible markup language (XML) for describing and exchanging data between applications. It is a platform independent markup language. It allows computers to store data in a format, which can be interpreted by any other computer system. XML can be used to transfer structures data between heterogeneous systems. 5) Explain about .NET services? .NET helps you to create software as web services. A web services is an application or business logic that is accessible through standard internet protocols such as HTTP and simple object access protocol. Users can subscribe to such a service and use it as long as they need it, regardless of the hardware and software platform.

6) Explain about .NET framework? It is the foundation on which you design, develop and deploy applications. It is consistent and simplified programming model that helps you to easily build robust applications. It forms the core of the .NET infrastructure because it exists as a layer between the .NET applications and the underlying operating system. 7) Explain about the Common language Runtime? The CLR is one of the most essential components of the .NET framework. CLR is the environment where all programs using .NET technologies are executed. It provides services such as code compilation, memory allocation, and garbage collection. It translates the code into Intermediate language which helps interoperability of code. 8) Explain about CLS? CLS consists of a set of common rules followed by all the languages of the .NET framework. This set of rules is known as Common language specifications. CLS enables an object or application to interact with the objects or applications of other languages. 9) Explain about CTS? One of the specifications defined in CLS is common type system (CTs), which provides a type system that is common across all languages. CTS define how data types are declared, used and managed in the code at run time. The size of integer and long variables is the same across all CLs compliant programming languages. 10) Explain the process of compilation in .NET? When you compile a program in .NET, the conversion of source code to machine language happens in two stages. In the first stage, the compiler translates code into an IL instead of machine language or assembly language. In the second stage the conversion of IL to machine language is done at run time by the JIt compiler. 11) Explain about managed heap? A managed heap is a region of the memory that is available for program execution. If sufficient memory is not available on the managed heap, the garbage collection process is invoked. Whenever you create an object, the CLR allocates memory for the object from the managed heap. 12) Explain about consistent programming model in .NET framework? The .NET Framework provides a common OOPs model across languages. This object model can be used in code to perform several tasks, such as reading from and writing to files, connecting to databases, and retrieving data. 13) Explain about Multi-Language integration? .Net allows multiple languages to be integrated. It is possible to create a class in VC# that derives from a class implemented in VB.NET. To enable objects with each other regardless of the language use to develop them, a set of language features has been defined in CLS. 14) Explain about Automatic resource management? While creating an application, a programmer may be required to write code for managing resources such as files, memory, network connections, and database resources. If a programmer does not free these resources, the application may not execute properly. This process is done by CLR automatically. 15) Explain about the features and elements present in Visual studio.NET IDE? Elements present in Visual studio IDE are toolbars, solution explorer, code editor, output window, task list window, and class view window. In addition to these elements start page and

project properties windows is also present. 16) Explain about solution explorer window? The solution explorer window lists the solution name, the project name, and all the classes that are used in the project. A particular file can be opened in a project by double clicking the file in the solution explorer window. 17) Explain about the Class view window? The class view window displays the classes, methods, and properties associated with a particular file. They are displayed in a hierarchical tree-view depicting the containership of these items. When you double-click any one of the items in the Class view window, it brings up the code editor window for that item.