Now Article Posting by Mails By Anyone

"Training Enhancers (A division of Network Enhancers - NETEN) now introduces anyone to post the artcles related to trainings, events, knowledge sharing, Technology advances of their respective domain in a simple way by mail to - trainingenhancers.blogpost@blogger.com"
All the articles will be reviewed manullay by the Moderator and if articles were found not relevant to the Blog, those articles will be removed.

/Training Enhancers Team
Showing posts with label Interview Questions. Show all posts
Showing posts with label Interview Questions. Show all posts

Sunday, 16 September 2012

.NET Software Technical Interview Questions - Part 3





ASP.NET AJAX Interview Questions




1. What is ASP.NET AJAX?
ASP.NET AJAX, mostly called AJAX, is a set of extensions of ASP.NET. It is developed by Microsoft to implement AJAX functionalities in Web applications. ASP.NET AJAX provides a set of components that enable the developers to develop applications that can update only a specified portion of data without refreshing the entire page. The ASP.NET AJAX works with the AJAX Library that uses object-oriented programming (OOP) to develop rich Web applications that communicate with the server using asynchronous postback.
2. What is the difference between synchronous postback and asynchronous postback?
The difference between synchronous and asynchronous postback is as follows:
  • Asynchronous postback renders only the required part of the page; whereas, synchronous postback renders the entire page for any postback.
  • Asynchronous postback executes only one postback at a time, that is, if you have two buttons doing asynchronous postback, the actions will be performed one by one; whereas, synchronous postback executes all the actions at once.
  • Asynchronous postback only modifies the update panel that raises the postback; whereas, synchronous postback modifies the entire page.
3. What technologies are being used in AJAX?
AJAX uses four technologies, which are as follows:
  • JavaScript
  • XMLHttpRequest
  • Document Object Model (DOM)
  • Extensible HTML (XHTML) and Cascading Style Sheets (CSS)
4. Why do we use the XMLHttpRequest object in AJAX?
The XMLHttpRequest object is used by JavaScript to transfer XML and other text data between client and server. The XMLHttpRequest object allows a client-side script to perform an HTTP request. AJAX applications use the XMLHttpRequest object so that the browser can communicate to the server without requiring a postback of the entire page. In earlier versions of Internet Explorer, MSXML ActiveX component is liable to provide this functionality; whereas, Internet Explorer 7 and other browsers, such as Mozilla Firefox,XMLHttpRequest is not liable to.
5. How can we get the state of the requested process?
XMLHttpRequest get the current state of the request operation by using the readyState property. This property checks the state of the object to determine if any action should be taken. The readyState property uses numeric values to represent the state.
6. What are the different controls of ASP.NET AJAX?
ASP.NET AJAX includes the following controls:
  • ScriptManager
  • ScriptManagerProxy
  • UpdatePanel
  • UpdateProgress
  • Timer



7. What are the new features included in the Microsoft AJAX library?
The Microsoft AJAX library is a client-based JavaScript library that is compatible with all modern browsers and offers a lot of functionality as compared to JavaScript. This library is released with new features and fully supports ASP.NET 4.0'. The new features included in the Microsoft AJAX library are as follows:
  • Imperative syntax - Supports simple imperative syntax that is used to create and manage controls.
  • Script loader - Retrieves all scripts that are needed by one or more client component or control automatically and executes the scripts in the order in which they are received.
  • Client data access - Supports to access client data and display by client data control and client template.
  • Client datacontext - Supports read and write permission to data from a database.
  • The AdoNetDataContext class - Enables you to easily interact with an ADO.NET Data Services service.
  • jQuery integration - Helps to access the elements in your Web pages, work with client-side events, enable visual effects, and make it easier to use AJAX in your applications.
8. Explain the Step property of the NumericUpDownExtender control.
The Step property sets the steps for numeric increment and decrement. The default value is 1.
9. What are the new features of ASP.NET AJAX 4.0?
ASP.NET 4.0 AJAX includes several new features that provide more functionality to a user. These features are as follows:
  • Support for live data binding.
  • Support for client-side template rendering.
  • Support for declarative instantiation of client components.
  • Support for using the observer pattern on JavaScript objects and arrays.
  • Support for invoking ADO.NET data services and data contexts.
  • Support for the DataView control.
10. Why do we use the UpdateProgress control in AJAX?
The UpdateProgress control is somewhat related to the UpdatePanel control. The UpdateProgress control enables you to design a user-friendly interface when a Web page consists of a number of UpdatePanel controls for partial-page rendering.

The UpdateProgress control makes you aware of the status information about the partial-page updates in theUpdatePanel control.
11. What is JSON?
JSON is an abbreviation of JavaScript Object Notation. It is a safe and reliable data interchange format in JavaScript, which is easy to understand not only for the users but also for the machines.
12. How many validation controls are available in ASP.NET AJAX 4.0?
The following validation controls are available in ASP.NET AJAX 4.0:
  • FilteredTextBoxExtender - Enables you to apply filtering to a text box.
  • MaskedEditExtender and MaskedEditValidator - Restricts a user to enter only a certain pattern of characters in the TextBox by applying a mask to the input.
  • ValidatorCalloutExtender - Attaches to the ASP.NET validators so that the error messages are not displayed as a simple text but as a balloon-style ToolTip.
  • NoBot - Prevents the spam/bot from filling the input forms automatically and uses the Completely Automated Public Turing test to tell Computers and Humans Apart (CAPTCHA), which is a type of challenge-response test to ensure that the response is not generated by the computer.
  • PasswordStrengthExtender - Measures the strength of the password text entered within the text box by validating with the different strength specified parameters



13. Explain the limitations of AJAX.
The following are the limitations of AJAX:
  • It is difficult to bookmark a particular state of the application.
  • Function provided in the code-behind file do not work because the dynamic pages cannot register themselves on browsers history engine automatically.
  • If JavaScript is disabled, then AJAX is not able to perform any work.
  • Response time may be slow because different controls of a page are loaded at different time.
14. What are the differences between AJAX and JavaScript?
The differences between AJAX and JavaScript are given as follows:
  • AJAX sends request to the server and does not wait for the response. It performs other operations on the page during that time. JavaScript make a request to the server and waits for response.
  • AJAX does not require the page to refresh for downloading the whole page while JavaScript manages and controls a Web page after being downloaded.
  • AJAX minimizes the overload on the server since the script needs to request once while JavaScript posts a request that updates the script every time.
15. Explain the UpdatePanel control.
The UpdatePanel control specifies the portions of a Web page that can be updated together. As theUpdatePanel control refreshes only a selected part of the Web page instead of refreshing the entire page with a postback, you get more flexibility to create rich and client-centric Web applications.

Refreshing a selected part of the Web page is referred as partial-page update. You can add one or moreUpdatePanel control in the Web page, which automatically participates in partial-page update without custom client script. The UpdatePanel control uses the UpdatePanel class to support the partial-page rendering.
16. What does the DynamicPopulateExtender control do?
The DynamicPopulateExtender control populates the contents of a control dynamically. It enables you to send an asynchronous call to the server that dynamically populates the contents of a control. TheDynamicPopulateExtender control replaces the contents of a control with the result of a Web service or page method call.
17. What does the MinimumPrefixLength property of the AutoCompleteExtender control do?
The MinimumPrefixLength property sets the minimum number of characters that must be entered before getting suggestions from the Web service.
18. What is the importance of client-side libraries?
Client-side libraries contain built-in code to make asynchronous calls over XMLHTTP. These libraries automatically handle browser compatibility issues. These libraries are based on a programming model similar to ASP.NET.



19. Can we call server-side code from JavaScript?
Yes, page methods and Web services are the two techniques to call the server-side code from JavaScript.
20. What are the components of the ASP.NET AJAX architecture?
You can divide the ASP.NET AJAX architecture into two components - AJAX client architecture and AJAX server architecture.
21. Describe AJAX Control Extender Toolkit.
AJAX Control Toolkit is a set of extenders that are used to extend the functionalities of the ASP.NET controls. The extenders use a block of JavaScript code to add new and enhanced capabilities to the ASP.NET controls. AJAX Control Toolkit is a free download available on the Microsoft site. You need to install this toolkit on your system before using extenders.
22. Explain the need of the Timer control in AJAX.
The Timer control is used with an UpdatePanel control to allow partial-page updates at a specified interval. It is mostly used when a periodically partial-page update for one or more UpdatePanel controls is required without refreshing the entire page.

The Timer control is a server control that sets a JavaScript component in the Web page. The interval property of the Timer control specifies time in milliseconds. Similar to the UpdatePanel control, the Timer control also requires an instance of the ScriptManager control in the Web page.

When the Timer control initiates a postback, the Tick event is raised on the server for which you can provide an event handler to perform the actions when the page is submitted to the server. The Tick event occurs when the time specified in the interval property has elapsed and the page is posted on the server. You can add one or more Timer controls on a Web page. Usually the entire page requires only a single Timer control; however, you can use multiple Timer controls, if the UpdatePanel controls are being updated at different intervals.
23. List the different states of XMLHttpRequest with their description.
The different states of the XMLHttpRequest object are as follows:
  • Uninitialized - Refers to the state when the object has not been initialized.
  • Open - Refers to the state when the object has been created; however, the send function has not been invoked.
  • Sent -Refers to the state when the send function is invoked; however, the status and headers are not available.
  • Receiving - Refers to the state when the process is receiving data.
  • Loaded - Refers to the state when the procedure is completed and the entire data is available.
24. Can we nest the UpdatePanel controls?
Yes, we can nest the UpdatePanel control.



25. What is the role of the ScriptManagerProxy control?
A Web page cannot contain more than one ScriptManager control. You can use the ScriptManagerProxycontrol to add scripts to other pages; however to perform such an operation, you need to work with a master page that contains the ScriptManager control. If you have only few pages that need to register to a script or a Web service, then you should remove these pages from the ScriptManager control and add them as individual pages by using the ScriptManagerProxy control. If you include the scripts on the master page by theScriptManager control, then the items get downloaded on each page that extends the master page, even if they are not necessary.
26. What is the work of the ConformOnFormSubmit property in the ConfirmButtonExtender control?
The ConformOnFormSubmit property determines whether or not the confirm dialog box should wait when the form is submitted for display.
27. What is the syntax to create AJAX objects?
AJAX uses the following syntax to create an object:

var myobject = new AjaxObject("page path");

The page path is the URL of the Web page containing the object that you want to call. The URL must be of the same domain as the Web page.
28. Is there any difference between HTML and XHTML?
Extensible HTML (XHTML) is a markup language that provides the mixture expressions of HTML and XML. XHTML is a flexible markup language that enables automated processing by standard XML tools, which was difficult in HTML.
29. What are the requirements to run ASP.NET AJAX applications on a server?
AJAX is a built-in functionality of .NET Framework 4.0. Therefore, you can run an AJAX application by just installing Microsoft Visual Studio 2010. However, to use extenders in your applications, you are required to install AJAX Control Toolkit and copy the AjaxControlToolkit.dll file to the Bin directory of your application.
30. Describe the situations in which AJAX should not be used.
You should not use AJAX if:
  • You want the page to show in a search engine, such as Google, because WebCrawler does not execute JavaScript code.
  • The browser does not support JavaScript.
  • You want to create a secure application.



31. What is the use of the ScriptManager control in AJAX?
The ScriptManager control is a core control that performs a key role in implementing the ASP.NET AJAX functionality. It helps to use JavaScript for the Microsoft AJAX Library. It should be noted that AJAX Library on a Web page can only be used if the Web page contains the ScriptManager control. This control makes use of theScriptManager class to maintain the AJAX script libraries and script files. It allows for partial page rendering, Web service calls, and use of ASP.NET AJAX Client Library by rendering the AJAX Library scripts to the browser.
32. How can you find out that an AJAX request has been completed?
You can find out that an AJAX request has been completed by using the readyState property. If the value of this property equals to four, it means that the request has been completed and the data is available.
33. Is it possible to use multiple ScriptManager controls on a Web page?
No, it is not possible.
34. What are the new controls introduced in ASP.NET AJAX Control Toolkit?
The following controls are introduced with the new version of AJAX Control Toolkit:
  • SeaDragonExtender control - Refers to the control that is used to deeply zoom the images. You can zoom in or out the image or the particular portion of the image by using the mouse. You can also create a menu over the Seadragon control. This control is helpful when you want to analyze the image closely.
  • AsyncFileUploadExtender control - Refers to the control that provides the facility to upload and save the files on the server asynchronously. You can check the outcome either at the server or client side.
35. Briefly describe ASP.NET AJAX Framework.
ASP.NET AJAX Framework provides a platform where developers can develop such type of applications that use the AJAX concept. The AJAX provides the collection of technologies to create dynamic pages at the client side. The JavaScript requests are responsible to retrieve data from the server or send data to the server. Even some processing at server also requires handling requests, such as searching and storing of data. These tasks are achieved more easily using the AJAX Framework.

AJAX Framework is completely devoted to process requests. The objective of the AJAX engine is to reduce the delays that the user notices while performing a postback to the server. AJAX Framework allows JavaScript functions to send requests to server at the client side. On the other side, it allows the server to process the client's request, searches data, and responds the result to the browser.
36. Is the AjaxControlToolkit.dll file installed in the Global Assembly Cache?
No, you have to copy this file to the Bin folder of your application.



37. What are the different ways to pass parameters to the server?
We can pass parameters to the server using either the GET or POST method. The following code snippets show the example of both the methods:
  • Get: XmlHttpObject.Open("GET", "file1.txt", true);
  • Post: XmlHttpObject.Open("POST", "file2.txt", true);
38. What are the extender controls?
The extender controls uses a block of JavaScript code to add new and enhanced capabilities to ASP.NET. The developers can use a set of sample extender controls through a separate download - AJAX Control Toolkit (ACT).
39. Describe the AccordionExtender control.
The AccordionExtender control is similar to the CollapsiblePanelExtender control. It allows you to group multiple collapsible panels in a single control. At the same time, it also manages the collapsed and expanded state of each panel; therefore, expanding one panel at a time. In other words, the AccordionExtender control does not support expanding two or more panels simultaneously. Instead, the header templates of all the panels are always visible so that you can click on any of them to display the hidden contents. By default, theAccordionExtender control opens with one panel as expanded.


Language-Integrated Query Language



1. What is Language Integrated Query (LINQ)?
LINQ is a programming model that is the composition of general-purpose standard query operators that allow you to work with data, regardless of the data source in any .NET based programming language. It is the name given to a set of technologies based on the integration of query capabilities into any .NET language.
2. What are LINQ query expressions?
A LINQ query, also known as a query expression, consists of a combination of query clauses that identify the data sources for the query. It includes instructions for sorting, filtering, grouping, or joining to apply to the source data. The LINQ query expressions syntax is similar to the SQL syntax. It specifies what information should be retrieved from the data source.
3. Write the basic steps to execute a LINQ query.
The following are the three basic steps to execute a LINQ query:
  • Obtain the data source (The data source can be either an SQL database or an XML file)
  • Create a query
  • Execute the query
4. Write the basic syntax of a LINQ query in Visual Basic as well as in C#.
In Visual Basic, the basic syntax of a LINQ query starts with the From clause and ends with the Select or Group By clause. In addition, you can use the Where, Order By, and Order By Descending clauses to perform additional functions, such as filtering data and generating the data in a specific order.

In C#, the basic syntax of a LINQ query starts with the From clause and ends with the Select or group by clause. In addition, you can use the where, orderby, and Orderby descending clauses to perform additional functions, such as filtering data and generating the data in a specific order.
5. In which statement the LINQ query is executed?
A LINQ query is executed in the For Each statement in Visual Basic and in the foreach statement in C#.
6. In LINQ, lambda expressions underlie many of the standard query operators. Is it True or False?
It is true.



7. What is PLINQ?
PLINQ stands for Parallel Language Integrated Query. It is the parallel implementation of LINQ, in which a query can be executed by using multiple processors. PLINQ ensures the scalability of software on parallel processors in the execution environment. It is used where data grows rapidly, such as in telecom industry or where data is heterogeneous.

PLINQ also supports all the operators of LINQ. In addition, you can query 'collections by using PLINQ. It can also run several LINQ queries simultaneously and makes use of the processors on the system. Apart from this, PLINQ uses parallel execution, which helps in running the queries quickly. Parallel execution provides a major performance improvement to PLINQ over certain types of legacy code, which takes too much time to execute.
8. What are the different Visual Basic features that support LINQ?
Visual Basic includes the following features that support LINQ:
  • Anonymous types - Enables you to create a new type based on a query result.
  • Implicitly typed variables - Enables the compiler to infer and assign a type when you declare and initialize a variable.
  • Extension method - Enables you to extend an existing type with your own methods without modifying the type itself.
9. What is the function of the DISTINCT clause in a LINQ query?
The DISTINCT clause returns the result set without the duplicate values.
10. What is the DataContext class and how is it related to LINQ?
After you add a LINQ to SQL Classes item to a project and open the O/R Designer, the empty design surface represents an empty DataContext class ready to be configured. The DataContext class is a LINQ to SQL class that acts as a conduit between a SQL Server database and the LINQ to SQL entity classes mapped to that database. This class contains the connection string information and the methods for connecting to a database and manipulating the data in the database. It is configured with connection information provided by the first item that is dragged onto the design surface.
11. What is the difference between the Take and Skip clauses?
The Take clause returns a specified number of elements. For example, you can use the Take clause to return two values from an array of numbers. The Skip clause skips the specified number of elements in the query and returns the rest. For example, you can use the Skip clause to skip the first four strings in an array of strings and return the remaining array of string.
12. What is Object Relational Designer (0/R Designer)?
The 0/R Designer provides a visual design surface to create LINQ to SQL entity classes and associations (relationships) that are based on objects in a database.



13. Which interface implements the standard query operators in LINQ?
The standard query operators implement the IEnumerable<T> or the IQueryable<T> interface in C# and theIEnumerable(Of T) or the IQueryable(Of T) interface in Visual Basic.
14. What are standard query operators in LINQ?
The standard query operators in LINQ are the extension methods that form the LINQ pattern. These operators form an API that enables querying of any .NET array or collection. It operates on sequences and allows you to perform operations, such as determining if a value exists in the sequence and performing an aggregated function, such as a summation over a sequence.
15. On what parameter does the GroupBy clause group the data?
The GroupBy clause groups the elements that share a common attribute.
16. What is a LinqDataSource control?
The LinqDataSource control enables you to use LINQ. in an ASP.NET Web page by setting the properties in the markup text. You can use the control retrieve or modify data. It is similar to the SqIDataSource andObjectDataSource controls in the sense that it can be used to declaratively bind other ASP.NET controls on a page to a data source. The difference is that instead of binding directly to a database or to a generic class, theLinqDataSource control is designed to bind a LINQ enabled data model.
17. How can you open the O/R Designer?
You can open the O/R Designer by adding a new LINQ to SQL Classes item to a project.
18. The standard query operators are themselves a set of extension methods that provide the LINQ query functionality for any type that implements the IEnumerable<T> interface in Visual Basic. Is it True or False?
False, as it implements the IEnumerable(T) interface in Visual Basic and the IEnumerable<T> interface is implemented in C#.



19. What are lambda expressions in LINQ?
A lambda expression is a function without a name that calculates and returns a single value. All lambda expressions use the lambda operator =>, which read as goes to. The left side of the lambda operator specifies the input parameters and the right side holds the expression or statement block.
20. Before you query a DataSet object by using LINQ to DataSet, you must first populate the dataset How can you do this?
You can load the data into the dataset by using different methods, such as:
  • Using the DataAdapter class
  • Using LINQ to SQL
21. What are the different implementations of LINQ?
The different implementations of LINQ are:
  • LINQ to SQL - Refers to a component of.NET Framework version 3.5 that provides a run-time infrastructure to manage relational data as objects.
  • LINQ to DataSet - Refers to a component that makes it easier and faster to query over data cached in a DataSet object.
  • LINQ to XML - Provides an in-memory XML programming interface.
  • LINQ to Objects - Refers to the use of LINQ queries with any IEnumerable or IEnumerable(T)collection directly, without the use of an intermediate LINQ provider or API, such as LINQ to SQL or LINQ to XML.
22. Which command-line tool generates code and mapping for the LINQ to SQL component of .NET Framework?
The SqlMetal.exe command-line tool generates code and map the LINQ to SQL component.
23. Name the control that exposes the LINQ features to Web developers through the ASP.NET data-source control architecture.
The LinqDataSource control exposes the LINQ features to Web developers through the ASP.NET data-source control architecture.
24. What is the difference between the Select clause and SelectMany() method in LINQ?
Both the Select clause and SelectMany() method are used to produce a result value from a source of values. The difference lies in the result set. The Select clause is used to produce one result value for every source value. The result value is a collection that has the same number of elements from the query. In contrast, theSelectMany() method produces a single result that contains a concatenated collection from the query.



25. Which extension method do you need to run a parallel query in PLINQ?
The AsParallel extension method is required to run a parallel query in PLINQ.









Wednesday, 12 September 2012

.NET Technical Interview Question - Part 2




.NET Programming Concepts Questions



1. Define variable and constant.
A variable can be defined as a meaningful name that is given to a data storage location in the computer memory that contains a value. Every variable associated with a data type determines what type of value can be stored in the variable, for example an integer, such as 100, a decimal, such as 30.05, or a character, such as 'A'.

You can declare variables by using the following syntax:

<Data_type> <variable_name> ;

A constant is similar to a variable except that the value, which you assign to a constant, cannot be changed, as in case of a variable. Constants must be initialized at the same time they are declared. You can declare constants by using the following syntax:

const int interestRate = 10;
2. What is a data type? How many types of data types are there in .NET ?
A data type is a data storage format that can contain a specific type or range of values. Whenever you declare variables, each variable must be assigned a specific data type. Some common data types include integers, floating point, characters, and strings. The following are the two types of data types available in .NET:
  • Value type - Refers to the data type that contains the data. In other words, the exact value or the data is directly stored in this data type. It means that when you assign a value type variable to another variable, then it copies the value rather than copying the reference of that variable. When you create a value type variable, a single space in memory is allocated to store the value (stack memory). Primitive data types, such as int, float, and char are examples of value type variables.
  • Reference type - Refers to a data type that can access data by reference. Reference is a value or an address that accesses a particular data by address, which is stored elsewhere in memory (heap memory). You can say that reference is the physical address of data, where the data is stored in memory or in the storage device. Some built-in reference types variables in .Net are string, array, and object.
3. Mention the two major categories that distinctly classify the variables of C# programs.
Variables that are defined in a C# program belong to two major categories: value type and reference type. The variables that are based on value type contain a value that is either allocated on a stack or allocated in-line in a structure. The variables that are based on reference types store the memory address of a variable, which in turn stores the value and are allocated on the heap. The variables that are based on value types have their own copy of data and therefore operations done on one variable do not affect other variables. The reference-type variables reflect the changes made in the referring variables.

Predict the output of the following code segment:
int x = 42; 
int y = 12;
int w;
object o;
o = x;
w = y * (int)o; 
Console.WriteLine(w);

/* The output of the code is 504. */
4. Which statement is used to replace multiple if-else statements in code.
In Visual Basic, the Select-Case statement is used to replace multiple If - Else statements and in C#, theswitch-case statement is used to replace multiple if-else statements.
5. What is the syntax to declare a namespace in .NET?
In .NET, the namespace keyword is used to declare a namespace in the code.

The syntax for declaring a namespace in C# is:
namespace UserNameSpace;

The syntax for declaring a namespace in VB is:
Namespace UserNameSpace
6. What is the difference between constants and read-only variables that are used in programs?
Constants perform the same tasks as read-only variables with some differences. The differences between constants and read-only are

Constants:
  1. Constants are dealt with at compile-time.
  2. Constants supports value-type variables.
  3. Constants should be used when it is very unlikely that the value will ever change.

Read-only:
  1. Read-only variables are evaluated at runtime.
  2. Read-only variables can hold reference type variables.
  3. Read-only variables should be used when run-time calculation is required.



7. Differentiate between the while and for loop in C#.
The while and for loops are used to execute those units of code that need to be repeatedly executed, unless the result of the specified condition evaluates to false. The only difference between the two is in their syntax. The for loop is distinguished by setting an explicit loop variable.
8. What is an identifier?
Identifiers are northing but names given to various entities uniquely identified in a program. The name of identifiers must differ in spelling or casing. For example, MyProg and myProg are two different identifiers. Programming languages, such as C# and Visual Basic, strictly restrict the programmers from using any keyword as identifiers. Programmers cannot develop a class whose name is public, because, public is a keyword used to specify the accessibility of data in programs.
9. What does a break statement do in the switch statement?
The switch statement is a selection control statement that is used to handle multiple choices and transfer control to the case statements within its body. The following code snippet shows an example of the use of theswitch statement in C#: 
switch(choice)
{
 case 1:
 console.WriteLine("First"); 
 break;
 case 2:
 console.WriteLine("Second");
 break;
 default:
 console.WriteLine("Wrong choice");
 break;
}

In switch statements, the break statement is used at the end of a case statement. The break statement is mandatory in C# and it avoids the fall through of one case statement to another.
10. Explain keywords with example.
Keywords are those words that are reserved to be used for a specific task. These words cannot be used as identifiers. You cannot use a keyword to define the name of a variable or method. Keywords are used in programs to use the features of object-oriented programming.

For example, the abstract keyword is used to implement abstraction and the inherits keyword is used to implement inheritance by deriving subclasses in C# and Visual Basic, respectively.

The new keyword is universally used in C# and Visual Basic to implement encapsulation by creating objects.
11. Briefly explain the characteristics of value-type variables that are supported in the C# programming language.
The variables that are based on value types directly contain values. The characteristics of value-type variables that are supported in C# programming language are as follows:
  • All value-type variables derive implicitly from the System.ValueType class
  • You cannot derive any new type from a value type
  • Value types have an implicit default constructor that initializes the default value of that type
  • The value type consists of two main categories:
    • Structs - Summarizes small groups of related variables.
    • Enumerations - Consists of a set of named constants.
12. Give the syntax of using the while loop in a C# program.
The syntax of using the while loop in C# is: 
while(condition) //condition
{
 //statements
}
You can find an example of using the while loop in C#:
int i = 0;
while(i < 5)
{
 Console.WriteLine("{0} ", i);
 i++;
}

The output of the preceding code is: 0 1 2 3 4 .



13. What is a parameter? Explain the new types of parameters introduced in C# 4.0.
A parameter is a special kind of variable, which is used in a function to provide a piece of information or input to a caller function. These inputs are called arguments. In C#, the different types of parameters are as follows:
  • Value type - Refers that you do not need to provide any keyword with a parameter.
  • Reference type - Refers that you need to mention the ref keyword with a parameter.
  • Output type - Refers that you need to mention the out keyword with a parameter.
  • Optional parameter - Refers to the new parameter introduced in C# 4.0. It allows you to neglect the parameters that have some predefined default values. The example of optional parameter is as follows:
    public int Sum(int a, int b, int c = 0, int d = 0); /* c and d is optional */
    Sum(10, 20); //10 + 20 + 0 + 0
    Sum(10, 20, 30); //10 + 20 + 30 + 0
    Sum(10, 20, 30, 40); //10 + 20 + 30 + 40
    
  • Named parameter - Refers to the new parameter introduced in C# 4.0. Now you can provide arguments by name rather than position. The example of the named parameter is as follows:
    public void CreateAccount(string name, string address = "unknown", int age = 0);
    CreateAccount("Sara", age: 30);
    CreateAccount(address: "India", name: "Sara");
    
14. Briefly explain the characteristics of reference-type variables that are supported in the C# programming language.
The variables that are based on reference types store references to the actual data. The keywords that are used to declare reference types are:
  1. Class - Refers to the primary building block for the programs, which is used to encapsulate variables and methods into a single unit.
  2. Interface - Contains only the signatures of methods, properties, events, or indexers.
  3. Delegate - Refers to a reference type that is used to encapsulate a named or anonymous method.
15. What are the different types of literals?
A literal is a textual representation of a particular value of a type.

The different types of literals in Visual Basic are:
  • Boolean Literals - Refers to the True and False literals that map to the true and false state, respectively.
  • Integer Literals - Refers to literals that can be decimal (base 10), hexadecimal (base 16), or octal (base 8).
  • Floating-Point Literals - Refers to an integer literal followed by an optional decimal point By default, a floating-point literal is of type Double.
  • String Literals - Refers to a sequence of zero or more Unicode characters beginning and ending with an ASCII double-quote character.
  • Character Literals - Represents a single Unicode character of the Char type.
  • Date Literals - Represents time expressed as a value of the Date type.
  • Nothing - Refers to a literal that does not have a type and is convertible to all types in the type system.

The different types of literals in C# are:
  • Boolean literals - Refers to the True and False literals that map to the true and false states, respectively.
  • Integer literals - Refers to literals that are used to write values of types int, uint, long, and ulong.
  • Real literals - Refers to literals that are used to write values of types float, double, and decimal.
  • Character literals - Represents a single character that usually consists of a character in quotes, such as 'a'.
  • String literals - Refers to string literals, which can be of two types in C#:
    • A regular string literal consists of zero or more characters enclosed in double quotes, such as "hello".
    • A verbatim string literal consists of the @ character followed by a double-quote character, such as @"hello".
  • The Null literal - Represents the null-type.
16. What is the main difference between sub-procedure and function?
The sub-procedure is a block of multiple visual basic statements within Sub and End Sub statements. It is used to perform certain tasks, such as changing properties of objects, receiving or processing data, and displaying an output. You can define a sub-procedure anywhere in a program, such as in modules, structures, and classes.

We can also provide arguments in a sub-procedure; however, it does not return a new value.
The function is also a set of statements within the Function and End Function statements. It is similar to sub-procedure and performs the same task. The main difference between a function and a sub-procedure is that sub-procedures do not return a value while functions do.
17. Determine the output of the code snippet.
int a = 29;
a--;
a -= ++a;
Console.WriteLine("The value of a is: {0}", a);

/* The output of the code is -1. */
18. Differentiate between Boxing and Unboxing.
When a value type is converted to an object type, the process is known as boxing; whereas, when an object type is converted to a value type, the process is known as unboxing.

Boxing and unboxing enable value types to be treated as objects. Boxing a value type packages it inside an instance of the Object reference type. This allows the value type to be stored on the garbage collected heap. Unboxing extracts the value type from the object. In this example, the integer variable i is boxed and assigned to object obj.

Example:
int i = 123;
object obj = i; /* Thi line boxes i. */ 

/* The object obj can then be unboxed and assigned to integer variable i: */
i = (int)obj; // unboxing



19. Give the syntax of using the for loop in C# code?
The syntax of using the for loop in C# code is given as follows: 
for(initializer; condition; loop expression)
{
 //statements
}

In the preceding syntax, initializer is the initial value of the variable, condition is the expression that is checked before the execution of the for loop, and loop expression either increments or decrements the loop counter.

The example of using the for loop in C# is shown in the following code snippet:
for(int i = 0; i < 5; i++)
 Console.WriteLine("Hello");

In the preceding code snippet, the word Hello will be displayed for five times in the output window.




ADO.NET Interview Questions




1. What is the full form of ADO?
The full form of ADO is ActiveX Data Object.
2. Explain ADO.NET in brief.
ADO.NET is a very important feature of .NET Framework, which is used to work with data that is stored in structured data sources, such as databases and XML files. The following are some of the important features of ADO.NET:
  • Contains a number of classes that provide you with various methods and attributes to manage the communication between your application and data source.
  • Enables you to access different data sources, such as Microsoft SQL Server, and XML, as per your requirements.
  • Provides a rich set of features, such as connection and commands that can be used to develop robust and highly efficient data services in .NET applications.
  • Provides various data providers that are specific to databases produced by various vendors. For example, ADO.NET has a separate provider to access data from Oracle databases; whereas, another provider is used to access data from SQL databases.
3. What are major difference between classic ADO and ADO.NET?
Following are some major differences between both
  • In ADO we have recordset and in ADO.NET we have dataset.
  • In recordset we can only have one table. If we want to accommodate more than one tables. We need to do inner join and fill the recordset. Dataset can have multiple tables.
  • All data persist in XML as compared to classic ADO where data persisted in Binary format also.
4. What are the two fundamental objects in ADO.NET?
DataReader and DataSet are the two fundamental objects in ADO.NET.
5. What are the benefits of using of ADO.NET in .NET 4.0.
The following are the benefits of using ADO.NET in .NET 4.0 are as follows:
  • Language-Integrated Query (LINQ) - Adds native data-querying capabilities to .NET languages by using a syntax similar to that of SQL. This means that LINQ simplifies querying by eliminating the need to use a separate query language. LINQ is an innovative technology that was introduced in .NET Framework 3.5.
  • LINQ to DataSet - Allows you to implement LINQ queries for disconnected data stored in a dataset. LINQ to DataSet enables you to query data that is cached in a DataSet object. DataSet objects allow you to use a copy of the data stored in the tables of a database, without actually getting connected to the database.
  • LINQ to SQL - Allows you to create queries for data stored in SQL server database in your .NET application. You can use the LINQ to SQL technology to translate a query into a SQL query and then use it to retrieve or manipulate data contained in tables of an SQL Server database. LINQ to SQL supports all the key functions that you like to perform while working with SQL, that is, you can insert, update, and delete information from a table.
  • SqlClient Support for SQL Server 2008 - Specifies that with the starting of .NET Framework version 3.5 Service Pack (SP) 1, .NET Framework Data Provider for SQL Server (System.Data.SqlClientnamespace) includes all the new features that make it fully compatible with SQL Server 2008 Database Engine.
  • ADO.NET Data Platform - Specifies that with the release of .NET Framework 3.5 Service Pack (SP) 1, an Entity Framework 3.5 was introduced that provides a set of Entity Data Model (EDM) functions. These functions are supported by all the data providers; thereby, reducing the amount of coding and maintenance in your application. In .NET Framework 4.0, many new functions, such as string, aggregate, mathematical, and date/time functions have been added.
6. Which namespaces are required to enable the use of databases in ASP.NET pages?
The following namespaces are required to enable the use of databases in ASP.NET pages:
  • The System.Data namespace.
  • The System.Data.OleDb namespace (to use any data provider, such as Access, Oracle, or SQL)
  • The System.Data.SQLClient namespace (specifically to use SQL as the data provider)



7. Explain the DataAdapter.Update() and DataSetAcceptChanges() methods.
The DataAdapter.Update() method calls any of the DML statements, such as the UPDATE, INSERT, or DELETEstatements, as the case may be to update, insert, or delete a row in a DataSet. TheDataSet.Acceptchanges() method reflects all the changes made to the row since the last time theAcceptChanges() method was called.
8. What is the meaning of object pooling?
Object pooling is a concept of storing a pool (group) of objects in memory that can be reused later as needed. Whenever, a new object is required to create, an object from the pool can be allocated for this request; thereby, minimizing the object creation. A pool can also refer to a group of connections and threads. Pooling, therefore, helps in minimizing the use of system resources, improves system scalability, and performance.
9. Which properties are used to bind a DataGridView control?
The DataSource property and the DataMember property are used to bind a DataGridView control.
10. What property must be set and what method must be called in your code to bind the data from some data source to the Repeater control?
You must set the DataSource property and call the DataBind() method.
11. Mention the namespace that is used to include .NET Data Provider for SQL server in .NET code.
The System.Data.SqlClient namespace.
12. What is the difference between OLEDB Provider and SqlClient?
With respect to usage, there is no difference between OLEDB Provider and SqlClient. The difference lies in their performance. SqlClient is explicitly used to connect your application to SQL server directly, OLEDB Provider is generic for various databases, such as Oracle and Access including SQL Server.

Therefore, there will be an overhead which leads to performance degradation.



13. Name the two properties of the GridView control that have to be specified to turn on sorting and paging.
The properties of the GridView control that need to be specified to turn on sorting and paging are as follows:
  • The AllowSorting property of the Gridview control indicates whether sorting is enabled or not. You should set the AllowSorting property to True to enable sorting.
  • The AllowPaging property of the Gridview control indicates whether paging is enabled or not. You should set the AllowPaging property to True to enable paging.
14. Mention different types of data providers available in .NET Framework.
  • .NET Framework Data Provider for SQL Server - Provides access to Microsoft SQL Server 7.0 or later version. It uses the System.Data.SqlClient namespace.
  • .NET Framework Data Provider for OLE DB - Provides access to databases exposed by using OLE DB. It uses the System.Data.OleDb namespace.
  • .NET Framework Data Provider for ODBC - Provides access to databases exposed by using ODBC. It uses the System.Data.Odbc namespace.
  • .NET Framework Data Provider for Oracle - Provides access to Oracle database 8.1.7 or later versions. It uses the System.Data.OracleClient namespace.
15. Which architecture does Datasets follow?
Datasets follow the disconnected data architecture.
16. What is the role of the DataSet object in ADO.NET?
One of the major component of ADO.NET is the DataSet object, which always remains disconnected from the database and reduces the load on the database.
17. What is a DataReader object?
The DataReader object helps in retrieving the data from a database in a forward-only, read-only mode. The base class for all the DataReader objects is the DbDataReader class.

The DataReader object is returned as a result of calling the ExecuteReader() method of the Command object. The DataReader object enables faster retrieval of data from databases and enhances the performance of .NET applications by providing rapid data access speed. However, it is less preferred as compared to theDataAdapter object because the DataReader object needs an Open connection till it completes reading all the rows of the specified table.

An Open connection to read data from large tables consumes most of the system resources. When multiple client applications simultaneously access a database by using the DataReader object, the performance of data retrieval and other related processes is substantially reduced. In such a case, the database might refuse connections to other .NET applications until other clients free the resources.
18. How can you identify whether or not any changes are made to the DataSet object since it was last loaded?
The DataSet object provides the following two methods to track down the changes: 
  • The GetChanges() method - Returns the DataSet object, which is changed since it was loaded or since the AcceptChanges() method was executed.
  • The HasChanges() method - Indicates if any changes occurred since the DataSet object was loaded or after a call to the AcceptChanges() method was made.

If you want to revert all changes since the DataSet object was loaded, use the RejectChanges() method.



19. Which property is used to check whether a DataReader is closed or opened?
The IsClosed property is used to check whether a DataReader is closed or opened. This property returns atrue value if a Data Reader is closed, otherwise a false value is returned.
20. Name the method that needs to be invoked on the DataAdapter control to fill the generated DataSet with data?
The Fill() method is used to fill the dataset with data.
21. What is the use of the Connection object?
The Connection object is used to connect your application to a specific data source by providing the required authentication information in connection string. The connection object is used according to the type of the data source. For example, the OleDbConnection object is used with an OLE-DB provider and the SqlConnectionobject is used with an MS SQL Server.
22. What is the use of the CommandBuilder class?
The CommandBuilder class is used to automatically update a database according to the changes made in aDataSet.

This class automatically registers itself as an event listener to the RowUpdating event. Whenever data inside a row changes, the object of the CommandBuilder class automatically generates an SQL statement and uses theSelectCommand property to commit the changes made in DataSet.

OLEDB provider in .NET Framework has the OleDbCommandBuiider class; whereas, the SQL provider has theSqlCommandBuilder class.
23. Explain the architecture of ADO.NET in brief.
AD0.NET consists of two fundamental components:
  • The DataSet, which is disconnected from the data source and does not need to know where the data that it holds is retrieved from.
  • The .net data provider, which allows you to connect your application to the data source and execute the SQL commands against it.

The data provider contains the Connection, Command, DataReader, and DataAdapter objects. TheConnection object provides connectivity to the database. The Command object provides access to database commands to retrieve and manipulate data in a database. The DataReader object retrieves data from the database in the readonly and forward-only mode. The DataAdapter object uses Command objects to execute SQL commands. The DataAdapter object loads the DataSet object with data and also updates changes that you have made to the data in the DataSet object back to the database.
24. Describe the disconnected architecture of ADO.NET's data access model.
ADO.NET maintains a disconnected database access model, which means, the application never remains connected constantly to the data source. Any changes and operations done on the data are saved in a local copy (dataset) that acts as a data source. Whenever, the connection to the server is re-established, these changes are sent back to the server, in which these changes are saved in the actual database or data source.



25. What are the usages of the Command object in ADO.NET?
The following are the usages of the Command object in AD0.NET:

The Command object in AD0.NET executes a command against the database and retrieves a DataReader orDataSet object.
  • It also executes the INSERT, UPDATE, or DELETE command against the database.
  • All the command objects are derived from the DbCommand class.
  • The command object is represented by two classes: SqlCommand and OleDbCommand.
  • The Command object provides three methods to execute commands on the database:
    • The ExecuteNonQuery() method executes the commands and does not return any value.
    • The ExecuteScalar() method returns a single value from a database query.
    • The ExecuteReader() method returns a result set by using the DataReader object.
26. What are the pre-requisites for connection pooling?
The prerequisites for connection pooling are as follows:
  • There must be multiple processes to share the same connection describing the same parameters and security settings.
  • The connection string must be identical.
27. What is connection pooling?
Connection pooling refers to the task of grouping database connections in cache to make them reusable because opening new connections every time to a database is a time-consuming process. Therefore, connection pooling enables you to reuse already existing and active database connections, whenever required, and increasing the performance of your application.

You can enable or disable connection pooling in your application by setting the pooling property to either true or false in connection string. By default, it is enabled in an application.
28. What are the various methods provided by the DataSet object to generate XML?
The various methods provided by the DataSet object to generate XML are:
  • ReadXml() - Reads XML document into a DataSet object.
  • GetXml() - Returns a string containing an XML document.
  • WriteXml() - Writes an XML data to disk.
29. Out of Windows authentication and SQL Server authentication, which authentication technique is considered as a trusted authentication method?
The Windows authentication technique is considered as a trusted authentication method because the username and password are checked with the Windows credentials stored in the Active Directory.

The SQL Server Authentication technique is not trusted as all the values are verified by SQL Server only.
30. How would you connect to a database by using .NET?
The connection class is used to connect a .NET application with a database.



31. Which adapter should you use, if you want to get the data from an Access database?
OleDbDataAdapter is used to get the data from an Access database.
32. Which object is used to add a relationship between two DataTable objects?
The DataRelation object is used to add relationship between two DataTable objects.
33. What are different types of authentication techniques that are used in connection strings to connect .NET applications with Microsoft SQL Server?
.NET applications can use two different techniques to authenticate and connect with SQL Server. These techniques are as follows:
  • The Windows Authentication option
  • The SQL Server Authentication option
34. Explain the new features in ADO.NET Entity Framework 4.0.
ADO.NET Entity Framework 4.0 is introduced in .NET Framework 4.0 and includes the following new features:
  • Persistence Ignorance - Facilitates you to define your own Plain Old CLR Objects (POCO) which are independent of any specific persistence technology.
  • Deferred or Lazy Loading - Specifies that related entities can be loaded automatically whenever required. You can enable lazy loading in your application by setting the DeferredLoadingEnabledproperty to true.
  • Self-Tracking Entities - Refers to the entities that are able to track their own changes. These changes can be passed across process boundaries and saved to the database.
  • Model-First Development - Allows you to create your own EDM and then generate relational model (database) from that EDM with matching tables and relations.
  • Built-in Functions - Enables you to use built-in SQL Server functions directly in your queries.
  • Model-Defined Functions - Enables you to use the functions that are defined in conceptual schema definition language (CSDL).
35. What is the difference between the Clone() and Copy() methods of the DataSet class?
The Clone() method copies only the structure of a DataSet. The copied structure includes all the relation, constraint, and DataTable schemas used by the DataSet. The Clone() method does not copy the data, which is stored in the DataSet.

The Copy() method copies the structure as well as the data stored in the DataSet.
36. What is the use of DataView?
User-defined view of a table is contained in a DataView. A complete table or a small section of table depending on some criteria can be presented by an object of the DataView class. You can use this class to sort and find data within DataTable.

The DataView class has the following methods:
  • Find() - Finds a row in a DataView by using sort key value.
  • FindRows() - Uses the sort key value to match it with the columns of DataRowView objects. It returns an array of all the corresponding objects of DataRowView whose columns match with the sort key value.
  • AddNew() - Adds a new row to the DataView object.
  • Delete() - Deletes the specified row from the DataView object according to the specified index.



37. What are the parameters that control most of connection pooling behaviors?
The parameters that control most of connection pooling behaviors are as follows:
  • Connect Timeout
  • Max Pool Size
  • Min Pool Size
  • Pooling
38. How can you add or remove rows from the DataTable object of DataSet?
The DataRowCollection class defines the collection of rows for the DataTable object in a DataSet. TheDataTable class provides the NewRow() method to add a new DataRow to DataTable. The NewRow method creates a new row, which implements the same schema as applied to the DataTable. The following are the methods provided by the DataRowCollection object:
  • Add() - Adds a new row to DataRowCollection.
  • Remove()- Removes a DataRow object from DataRowCollection.
  • RemoveAt() - Removes a row whose location is specified by an index number.
39. Explain in brief DataAdapter class in ADO.NET.
The DataAdapter class retrieves data from the database, stores data in a dataset, and reflects the changes made in the dataset to the database. The DataAdapter class acts as an intermediary for all the communication between the database and the DataSet object. The DataAdapter Class is used to fill a DataTable or DataSetObject with data from the database using the Fill() method. The DataAdapter class applies the changes made in dataset to the database by calling the Update() method.

The DataAdapter class provides four properties that represent the database command:

SelectCommand, InsertCommand, DeleteCommand, and UpdateCommand.