• No results found

What happens in memory when you Box and Unbox a value-type?

In document C#Interview Questions (Page 74-86)

6. When should you call the garbage collector in .NET?

As a good rule, you should not call the garbage collector. However, you could call the garbage collector when you are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory. However, this is usually not a good practice.

7. How do you convert a value-type to a reference-type?

Use Boxing.

8. What happens in memory when you Box and Unbox a value-type?

Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack.

(http://www.techinterviews.com/?p=57)

 What’s 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 it’s being operated on, a new instance is created.

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

 What’s 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.

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

 What’s the .NET datatype that allows the retrieval of data by a unique key?

HashTable.

 What’s class SortedList underneath? A sorted HashTable.

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

 What’s 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 {}.

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

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

 What’s a delegate? A delegate object encapsulates a reference to a method. In C++

they were referred to as function pointers.

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

 How’s 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.

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

 What’s 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.

 What namespaces are necessary to create a localized application?

System.Globalization, System.Resources.

 What’s the difference between // comments, /* */ comments and /// comments?

Single-line, multi-line and XML documentation comments.

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

 What’s the difference between <c> and <code> XML documentation tag? Single line code example and multiple-line code example.

 Is XML case-sensitive? Yes, so <Student> and <student> are different elements.

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

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

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

 What’s 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.

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

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

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

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

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

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

 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 it’s 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.

 What’s the role of the DataReader class in ADO.NET connections? It returns a read-only dataset from the data source when the command is executed.

 What is the wildcard character in SQL? Let’s 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%’.

 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 hasn’t), 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).

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

username and passwords).

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

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

 What does the parameter Initial Catalog define inside Connection String? The database name to connect to.

 What’s the data provider name to connect to Access database? Microsoft.Access.

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

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

Member function with a parameter...29 Multicast delegate calling static and member functions...30 From ... 63 From... 63 From... 64 From... 64 Structural Patterns ...65 Behavioral Patterns ...65 C# Interview Questions...67 (http://blogs.crsw.com/mark/articles/252.aspx)...67 Contents... 76 .NET Framework... 86 What is CTS... 86 What is a CLS...86 What is a Assembly...86 What is the difference between a namespace and an assembly name?...87 What is Manifest...87 What is GAC...87 What is concept of strong names...87 How to add and remove a assembly from GAC...87 What is an application domain...87 Structures:... 88 Classes:... 88 Class Modifier Table ...88 Member Accessibility...88 Member Modifiers...89 Instance Constructors:...89 Static Constructors:...89 Implement a Singleton using Static Constructor:...90 Nullable Types:... 90 Identity versus Equivalence...91 System.Object...91 Object.Equals Method...91

Object.ReferenceEquals Method...91 Collections... 91 Generics:... 91 Generic Types... 92 Delegates and Events...92 Covariance and contravariance...93 Inheritance versus composition: Which one should you choose?...93 Delayed Signing... 94 Casting Operators... 94 Implementing a C# Collection...94 Implementing Finalize and Dispose to Clean Up Unmanaged Resources...94 Finalize... 95 Dispose... 96 What size is a .NET object?...97 Can you prevent your class from being inherited by another class...97 Passing a Variable Number of Parameters to a Method...97 Dump Method Names using Reflection:...97 Dynamic Invocation using Relection:...98 Indexers... 98 Reflection:... 98 Obtaining a Type Object...98 Loading Assemblies...99 Browsing Type Information...99 Checked and UnChecked Operators...99 Difference between ReadOnly field and constant field...99 Advantage of anonymous delegate...99 Can a structure have default constructor...100 What is a satellite assembly...100 What is an appdomain?...100 What is boxing and Unboxing. ...100 What happens when a value type is added to an arraylist...100 What is serialization...100 Difference between ...100

Write a function in C# that will take one input parameter and return true if given input type is int or long else false?...100 What is static class? And how it is different from normal class?...100 What is the difference between ref and out keywords in C#?...100 What is delegate? What is the difference between delegate and event? 101 What is polymorphism? What is the importance of new and override

operators (key words) in terms of Polymorphism?...101 What is the difference between Array and Dictionary? When to use what?

... 101 What is the purpose of GAC? What are the prerequisites for putting a dll in GAC?... 101 What is the difference between "overload" and "override" in C#?...101 Memory Management:...101 Creational Patterns ...101 Abstract Factory - Creates an instance of several families of classes ....101 Builder - Separates object construction from its representation ...101 Factory Method - Creates an instance of several derived classes ...101 Prototype - A fully initialized instance to be copied or cloned ...101 Singleton - A class of which only a single instance can exist ...102 Structural Patterns ...102 Adapter - Match interfaces of different classes ...102 Bridge - Separates an object’s interface from its implementation ...102 Composite - A tree structure of simple and composite objects ...102 Decorator - Add responsibilities to objects dynamically ...102 Façade - A single class that represents an entire subsystem ...102 Flyweight - A fine-grained instance used for efficient sharing ...102 Proxy - An object representing another object ...102 Behavioral Patterns ...102

Chain of Responsibility - A way of passing a request between a chain of objects ... 102 Command - Encapsulate a command request as an object ...102 Interpreter - A way to include language elements in a program ...103 Iterator - Sequentially access the elements of a collection ...103 Mediator - Defines simplified communication between classes ...103

Memento - Capture and restore an object's internal state ...103 Observer - A way of notifying change to a number of classes ...103 State - Alter an object's behavior when its state changes ...103 Strategy - Encapsulates an algorithm inside a class ...103 Template Method - Defer the exact steps of an algorithm to a subclass ... 103 Visitor - Defines a new operation to a class without change...103 Which one of the following tools is used to view the metadata information contained in a .NET assembly?...121 1. What is the lifespan for items stored in ViewState?...122 What si the difference between interface and abstractclass...122 Maximum How Many Non-Clustor Index Created per Table?...123 Data in ViewState is in Which Form??...123 How many types of polymorphism in C#...123 What are the two methods to move from one webform to another webform ... 124 What are Managed Providers in .NET...124 Is multiple inheritance supported by c#?...124 what is the command for listing all permission sets using caspol...125 which command for listing all code groups using caspol...125 what are three policy in configuration files...125 WSDL is short form for...125 Which transport protocol is used to call webservies?...126 The process in which a web page sends data back to the same page on the server is called?... 126 Where is an asp.net form always submitted?...126 What data type does the RangeValidator control support?...127 Name the namespace for working with Data specific to IBM DB2?...127 what is the command for building the batch files in .Net Framework...127 What is diffrence between Int16,Int32,Int64 in C# ?...128 how many types of inheritance is supported by c#...128 How many types of JIT in present in ,Net ...128 I have triggers, views, functions, stored Procedures for a table

when I am dropping that table what are the objects deleted?...129

If you have two DLL files, how would you differentiate that which DLL is

belong to .Net ...129 In how many ways we can pass parameters through function call in

c#.net?... 129 Reflection reads information from the information store of assemblies

Reflection reads information from the information store of assemblies

does system .reflection store information about assemblies...130 The default type of enum is integer and has a default value 1...130 Unboxing of a null reference type will return a null...130 what is the difference between CLS and CTS?...131 if the code is like this;

byte a, b, c;

a = 255;

b = 122;

c = (byte)(a & b);

what will be the value of C?...131 Which of the following contains web application setup strings?...131 Difference between Override and Overload?...132 does c# support templates...132 What is the advantage of materialised View?...133 OLTP Stands for?...133 What's the maximum size of a row?...134 RAID stands for... 134 You ASP.NET application manages order entry data by using a DataSet object named orderEntry. The orderEntry object includes two DataTable objects named orderNames and OrderDetails. A ForeignKeyConstraint object named orderDetailsKey is defined between the two DataTable objects.

You attempt to delete a row in orderNames while there are related rows in OrderDetails, and an exception is generated.

What is the most likely cause of the problem? ...135 You create an ASP.NET application that contains confidential information. You use form-based authentication to validate users. You need to prevent

unauthenticated users from accessing the application. ...135 Which one of the following is not present in .NET Framework 1.1...136 Which one of the following is new in .NET Framework 2.0...136 How many generations are there in Garbage Collection...136

What is the core .NET Framework DLL...137 What are bubbled Events...137 what are the common properties in every validation control?...137 Order of methods fired during the page load?...138 What type of code is found in a Code-Behind class?...138 What are core components of SqlServer 2005 ...139 What property do you have to set to tell the grid which page to go to when using the Pager object?...139 What are the different types of assemblies available ?...139 How many classes can a single .NET DLL contain?...140 What data types do the RangeValidator control support?...140 Which of these string definitions will prevent escaping on backslashes in C#?

... 140 In a database we can able to create more than one primary key is it possible indirectly?... 141 How to make a field as read only in a datagrid?...141 Security is very important on any web site. By default, a .Net web site is configured with which of the following authentication types?...141 can we have protected element as a namespace member?...142 Can we use access specifiers like public,private etc with namespace

declaration?... 142 What is the default join in SQL Server2000?...142 When ever you use DROP Table option in Sql server 2000 the indexes related to that table also deleted or not?...143 Why can’t you specify the accessibility modifier for methods inside the

interface?... 143 Can multiple catch blocks be executed for a single try statement?...143 What class is underneath the SortedList class?...144 How can you sort the elements of the array in descending order?...144 What’s the difference between the System.Array.CopyTo() and

System.Array.Clone()?...144 You are a database developer for A Datum Corporation. You are creating a database that will store statistics for 15 different high school sports. 50 companies that publish sports information on their web sites will use this information. Each company's web site arranges and displays the statistics in a different format...145

The CLR handles registration at run time. True?...146 Which of the following incorrectly describe ASP.Net is?...146 Can As statement with Catch statement in error handling be omitted?...146 Which namespace will be included for using the MsgBox( ) of VB 6.0?...147 can it possible to omit a parameter to a procedure that expects a

ParamArray?...147 Is it possible to use a function's name as local variable inside the procedure?

... 147 Passing an array using ByRef or ByVal makes a difference if u use a ReDim statement inside the called procedure. Which array size will be affected?. .147 ParamArray arguments are passed by in a function?...148 In global.asax file which event will occur first when you invoke an application?

... 148 What is difference between "tlbexp" and "Regasm" tools?...148 Is a string a value type or a reference type ?...148 You use Visual Studio .NET to create a Windows-based application. The

application enables users to update customer information that is stored in a database.

Your application contains several text boxes. All TextBox controls are validated as soon as focus is transferred to another control. However, your validation code does not function as expected. To debug the application, you place the following line of code in the Enter event handler for the first text box:

Trace.WriteLine(“Enter);

You repeat the proc...149 1. You use Visual Studio .NET to create an application. Your application

contains two classes, Region and City, which are defined in the following code segment. (Line numbers are included for reference only)

01 public class Region {

02 public virtual void CalculateTax() { 03 // Code to calculate tax goes here.

04 } 05 }

06 public class City:Region {

07 public override void CalculateTax() { 08 // Insert new code.

09 } 10 }

You need to add code to the CalculateTax method of the City class to call t ... 150

What is the output of following C# code ?...150 What is the output of following C# code ?...152 What is the output of following C# code ?...152 What is the output of following C# code ?...153 Correction Number 2 ...*** How HR can "Help" to resolve any .NET

developer is professional or pirated software user ? ... Make years 2 and 1 year respectively instead of 3 in all three options...154

**** Correction : .NET Garbedge Collector (GC) mark object as ?

Make State , ... not sate every place...154 what is managed and unmanaged code?...154 Work Order of Garbedge Collector (GC) in .NET ?...155 The C# keyword ‘int’ maps to which .NET type?...155 Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace?...155 How do you implement thread synchronization (Object.Wait, Notify,and

CriticalSection) in C#? - ...155 Is it possible to have different access modifiers on the get/set methods of a property?... 156 How do you specify a custom attribute for the entire assembly (rather than for a class)? ...156 How do I simulate optional parameters to COM calls?...157 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?...157 What are the default user directory permissions when a Web site is created in IIS? ... 157 An application using cookie authentication was working fine on another

server. When moved to a new server, cookie authentication is not working correctly.

Which one of the following is the likely explanation of the above problem?

... 158 How to create class for holding data?...158 Event handling in .NET is handled by which feature...159 What is the value for i?

int i = 0;

while(i++ <10)

;

Console.WriteLine("i = " + i);...159

In document C#Interview Questions (Page 74-86)

Related documents