C# Interview Questions

General Questions:
  1. Does C# support multiple-inheritance?
  2. Who is a protected class-level variable available to?
    It is available to any sub-class (a class inheriting this class).
  3. Are private class-level variables inherited?
    Yes, but they are not accessible.  Although they are not visible or accessible via the class interface, they are inherited.
  4. Describe the accessibility modifier “protected internal”.
    It is available to classes that are within the same assembly and derived from the specified base class.
  5. What’s the top .NET class that everything is derived from?
  6. What does the term immutable mean?
    The data value may not be changed.  Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
  7. What’s the difference between System.String and System.Text.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.
  8. What’s the advantage of using System.Text.StringBuilder over System.String?
    StringBuilder is more efficient in cases where there is a large amount of string manipulation.  Strings are immutable, so each time a string is changed, a new instance in memory is created.
  9. Can you store multiple data types in System.Array?
  10. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
    The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array.  The CopyTo() method copies the elements into another existing array.  Both perform a shallow copy.  A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array.  A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.
  11. How can you sort the elements of the array in descending order?
    By calling Sort() and then Reverse() methods.
  12. What’s the .NET collection class that allows an element to be accessed using a unique key?
  13. What class is underneath the SortedList class?
    A sorted HashTable.
  14. Will the finally block get executed if an exception has not occurred?­
  15. What’s the C# syntax to catch 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 {}.

What's the difference between a programming language, a scripting language?

What's the difference between a programming language, a scripting language?

The main difference between a "programming language" (C, C++ etc.) and a "scripting language" (ASP, JSP, JavaScript, VBScript) is that code written in a programming language needs to be compiled before it is run. Once it is compiled, it can be run any number of times.

Scripting languages, on the other hand, are interpreted at run-time. This means that every time you want to run the program, a separate program needs to read the code, interpret it, and then follow the instructions in the code. Compiled code has already been interpreted into machine language, so it is will typically execute faster because the conversion into machine language has already been done.


Useful Shortcut: for windows

Useful Shortcut:
Start + M: Minimizes all open windows
Start + Shift + M: Maximizes All Windows
Start + E: Runs Windows Explorer
Start + R: Open the RUN Dialog Box
Start + F: Open the Search Results Dialog box
Start + CTRL + F: Opens the Search Results-Computer dialog Box (if the computer is connected to a network)
Start + Pause (Break): Opens the System Properties Dialog Box

Windows System Key Combinations:
F1: Help
CTRL + ESC: Open Start menu
ALT + TAB: Switch between open programs
ALT + F4: Quit program
SHIFT + DELETE: Delete item permanently

Windows Program Key Combinations:
CTRL + C: Copy
CTRL + X: Cut
CTRL + V: Paste
CTRL + Z: Undo
CTRL + B: Bold
CTRL + U: Underline
CTRL + I: Italic

Mouse Click/Keyboard Modifier Combinations for Shell Objects:
SHIFT + right click: Displays a shortcut menu containing alternative commands
SHIFT + double click: Runs the alternate default command (the second item on the menu)
ALT + double click: Displays properties
SHIFT + DELETE: Deletes an item immediately without placing it in the Recycle Bin

General Keyboard-Only Commands:
F1: Starts Windows Help
F10: Activates menu bar options
SHIFT + F10: Opens a shortcut menu for the selected item (this is the same as right-clicking an object
CTRL + ESC: Opens the Start menu (use the ARROW keys to select an item)
CTRL + ESC or ESC: Selects the Start button (press TAB to select the taskbar, or press SHIFT+F10 for a context menu)
ALT + DOWN ARROW: Opens a drop-down list box
ALT + TAB: Switch to another running program (hold down the ALT key and then press the TAB key to view the task-switching window)
SHIFT: Press and hold down the SHIFT key while you insert a CD-ROM to bypass the automatic-run feature
ALT + SPACE: Displays the main window's System menu (from the System menu, you can restore, move, resize, minimize, maximize, or close the window)
ALT +- (ALT + hyphen): Displays the Multiple Document Interface (MDI)child window's System menu (from the MDI child window's System menu, you can restore, move, resize, minimize, maximize, or close the child window)
CTRL + TAB: Switch to the next child window of a Multiple Document Interface (MDI) program
ALT + underlined letter in menu: Opens the menu
ALT + F4: Closes the current window
CTRL + F4: Closes the current Multiple Document Interface (MDI) window
ALT + F6: Switch between multiple windows in the same program (for example, when the Notepad Find dialog box is displayed
ALT + F6: switches between the Find dialog box and the main Notepad window)

Shell Objects and General Folder/Windows Explorer Shortcuts For a selected object:
F2: Rename object
F3: Find all files
CTRL + X: Cut
CTRL + C: Copy
CTRL + V: Paste
SHIFT + DELETE: Delete selection immediately, without moving the item to the Recycle Bin
ALT + ENTER: Open the properties for the selected object
To Copy a File: Press and hold down the CTRL key while you drag the file to another folder.
To Create a Shortcut: Press and hold down CTRL+SHIFT while you drag a file to the desktop or a folder.

General Folder/Shortcut Control:
F4: Selects the Go To A Different Folder box and moves down the entries in the box (if the toolbar is active in Windows Explorer)
F5: Refreshes the current window.
F6: Moves among panes in Windows Explorer
CTRL + G: Opens the Go To Folder tool (in Windows 95 Windows Explorer only)
CTRL + Z: Undo the last command
CTRL + A: Select all the items in the current window
BACKSPACE: Switch to the parent folder
SHIFT + click + Close button: For folders, close the current folder plus all parent folders

Windows Explorer Tree Control: Numeric Keypad *: Expands everything under the current selection
Numeric Keypad +: Expands the current selection
Numeric Keypad -: Collapses the current selection.
RIGHT ARROW: Expands the current selection if it is not expanded, otherwise goes to the first child
LEFT ARROW: Collapses the current selection if it is expanded, otherwise goes to the parent

Properties Control:
CTRL + TAB/CTRL + SHIFT + TAB: Move through the property tabs

Accessibility Shortcuts:

Press SHIFT five times: Toggles StickyKeys on and off
Press down and hold the right SHIFT key for eight seconds: Toggles FilterKeys on and off
Press down and hold the NUM LOCK key for five seconds: Toggles ToggleKeys on and off
Left ALT + left SHIFT+NUM LOCK: Toggles MouseKeys on and off
Left ALT + left SHIFT+PRINT SCREEN: Toggles high contrast on and off

Microsoft Natural Keyboard Keys: Windows Logo: Start menu
Windows Logo + R: Run dialog box
Windows Logo + M: Minimize all
SHIFT + Windows Logo+M: Undo minimize all
Windows Logo + F1: Help
Windows Logo + E: Windows Explorer
Windows Logo + F: Find files or folders
Windows Logo + D: Minimizes all open windows and displays the desktop
CTRL + Windows Logo + F: Find computer
CTRL + Windows Logo + TAB: Moves focus from Start, to the Quick Launch toolbar, to the system tray (use RIGHT ARROW or LEFT ARROW to move focus to items on the Quick Launch toolbar and the system tray)
Windows Logo + TAB: Cycle through taskbar buttons
Windows Logo + Break: System Properties dialog box
Application key: Displays a shortcut menu for the selected item

Microsoft Natural Keyboard with IntelliType Software Installed:
Windows Logo + L: Log off Windows
Windows Logo + P: Starts Print Manager
Windows Logo + C: Opens Control Panel
Windows Logo + V: Starts Clipboard
Windows Logo + K: Opens Keyboard Properties dialog box
Windows Logo + I: Opens Mouse Properties dialog box
Windows Logo + A: Starts Accessibility Options (if installed)
Windows Logo + SPACEBAR: Displays the list of Microsoft IntelliType shortcut keys
Windows Logo + S: Toggles CAPS LOCK on and off
Dialog Box Keyboard Commands: TAB: Move to the next control in the dialog box
SHIFT + TAB: Move to the previous control in the dialog box
SPACEBAR: If the current control is a button, this clicks the button. If the current control is a check box, this toggles the check box. If the current control is an option, this selects the option.
ENTER: Equivalent to clicking the selected button (the button with the outline)
ESC: Equivalent to clicking the Cancel button
ALT + underlined letter in dialog box item: Move to the corresponding item


ASP.NET Interview Questions

Difference between thread and process?

Thread - is used to execute more than one program at a time.
process - executes single program

Explain Namespace.

Namespaces are logical groupings of names used within a program. There may be multiple namespaces in a single application code, grouped based on the identifiers’ use. The name of any given identifier must appear only once in its namespace.
List the types of Authentication supported by ASP.NET.

Windows (default)
None (Security disabled)
What is CLR?

Common Language Runtime (CLR) is a run-time environment that manages the execution of .NET code and provides services like memory management, debugging, security, etc. The CLR is also known as Virtual Execution System (VES).
What is CLI?

The CLI is a set of specifications for a runtime environment, including a common type system, base class library, and a machine-independent intermediate code known as the Common Intermediate Language (CIL).
List the various stages of Page-Load lifecycle.

o Init()
o Load()
o PreRender()
o Unload()
Explain Assembly and Manifest.

An assembly is a collection of one or more files and one of them (DLL or EXE) contains a special metadata called Assembly Manifest. The manifest is stored as binary data and contains details like versioning requirements for the assembly, the author, security permissions, and list of files forming the assembly. An assembly is created whenever a DLL is built. The manifest can be viewed programmatically by making use of classes from the System.Reflection namespace. The tool Intermediate Language Disassembler (ILDASM) can be used for this purpose. It can be launched from the command prompt or via Start> Run.
What is Shadow Copy?

In order to replace a COM component on a live web server, it was necessary to stop the entire website, copy the new files and then restart the website. This is not feasible for the web servers that need to be always running. .NET components are different. They can be overwritten at any time using a mechanism called Shadow Copy. It prevents the Portable Executable (PE) files like DLLs and EXEs from being locked. Whenever new versions of the PEs are released, they are automatically detected by the CLR and the changed components will be automatically loaded. They will be used to process all new requests not currently executing, while the older version still runs the currently executing requests. By bleeding out the older version, the update is completed.
What is DLL Hell?

DLL hell is the problem that occurs when an installation of a newer application might break or hinder other applications as newer DLLs are copied into the system and the older applications do not support or are not compatible with them. .NET overcomes this problem by supporting multiple versions of an assembly at any given time. This is also called side-by-side component versioning.
Explain Web Services.

Web services are programmable business logic components that provide access to functionality through the Internet. Standard protocols like HTTP can be used to access them. Web services are based on the Simple Object Access Protocol (SOAP), which is an application of XML. Web services are given the .asmx extension.
Explain Windows Forms.

Windows Forms is employed for developing Windows GUI applications. It is a class library that gives developers access to Windows Common Controls with rich functionality. It is a common GUI library for all the languages supported by the .NET Framework.
What is Postback?

When an action occurs (like button click), the page containing all the controls within the <FORM... > tag performs an HTTP POST, while having itself as the target URL. This is called Postback.
Explain the differences between server-side and client-side code?

Server side scripting means that all the script will be executed by the server and interpreted as needed. Client side scripting means that the script will be executed immediately in the browser such as form field validation, clock, email validation, etc. Client side scripting is usually done in VBScript or JavaScript. Since the code is included in the HTML page, anyone can see the code by viewing the page source. It also poses as a possible security hazard for the client computer.
Enumerate the types of Directives.

@ Page directive
@ Import directive
@ Implements directive
@ Register directive
@ Assembly directive
@ OutputCache directive
@ Reference directive

What is Code-Behind?

Code-Behind is a concept where the contents of a page are in one file and the server-side code is in another. This allows different people to work on the same page at the same time and also allows either part of the page to be easily redesigned, with no changes required in the other. An Inherits attribute is added to the @ Page directive to specify the location of the Code-Behind file to the ASP.NET page.
Describe the difference between inline and code behind.

Inline code is written along side the HTML in a page. There is no separate distinction between design code and logic code. Code-behind is code written in a separate file and referenced by the .aspx page.
List the ASP.NET validation controls?

What is Data Binding?

Data binding is a way used to connect values from a collection of data (e.g. DataSet) to the controls on a web form. The values from the dataset are automatically displayed in the controls without having to write separate code to display them.
Describe Paging in ASP.NET.

The DataGrid control in ASP.NET enables easy paging of the data. The AllowPaging property of the DataGrid can be set to True to perform paging. ASP.NET automatically performs paging and provides the hyperlinks to the other pages in different styles, based on the property that has been set for PagerStyle.Mode.
Should user input data validation occur server-side or client-side? Why?

All user input data validation should occur on the server and minimally on the client-side, though it is a good way to reduce server load and network traffic because we can ensure that only data of the appropriate type is submitted from the form. It is totally insecure. The user can view the code used for validation and create a workaround for it. Secondly, the URL of the page that handles the data is freely visible in the original form page. This will allow unscrupulous users to send data from their own forms to your application. Client-side validation can sometimes be performed where deemed appropriate and feasible to provide a richer, more responsive experience for the user.
What is the difference between Server.Transfer and Response.Redirect?

* Response. Redirect: This tells the browser that the requested page can be found at a new location. The browser then initiates another request to the new page loading its contents in the browser. This results in two requests by the browser.
* Server. Transfer: It transfers execution from the first page to the second page on the server. As far as the browser client is concerned, it made one request and the initial page is the one responding with content. The benefit of this approach is one less round trip to the server from the client browser. Also, any posted form variables and query string parameters are available to the second page as well.
What is an interface and what is an abstract class?

In an interface, all methods must be abstract (must not be defined). In an abstract class, some methods can be defined. In an interface, no accessibility modifiers are allowed, whereas it is allowed in abstract classes.
Session state vs. View state:

In some cases, using view state is not feasible. The alternative for view state is session state. Session state is employed under the following situations:
o Large amounts of data - View state tends to increase the size of both the HTML page sent to the browser and the size of form posted back. Hence session state is used.
o Secure data - Though the view state data is encoded and may be encrypted, it is better and secure if no sensitive data is sent to the client. Thus, session state is a more secure option.
o Problems in serializing of objects into view state - View state is efficient for a small set of data. Other types like DataSet are slower and can generate a very large view state.
Can two different programming languages be mixed in a single ASPX file?

ASP.NET’s built-in parsers are used to remove code from ASPX files and create temporary files. Each parser understands only one language. Therefore mixing of languages in a single ASPX file is not possible.
Is it possible to see the code that ASP.NET generates from an ASPX file?

By enabling debugging using a <%@ Page Debug="true" %> directive in the ASPX file or a <compilation debug="true"> statement in Web.config, the generated code can be viewed. The code is stored in a CS or VB file (usually in the \%SystemRoot%\Microsoft.NET\Framework\v1.0.nnnn\Temporary ASP.NET Files).
Can a custom .NET data type be used in a Web form?

This can be achieved by placing the DLL containing the custom data type in the application root's bin directory and ASP.NET will automatically load the DLL when the type is referenced.
List the event handlers that can be included in Global.asax?

o Application start and end event handlers
o Session start and end event handlers
o Per-request event handlers
o Non-deterministic event handlers
Can the view state be protected from tampering?

This can be achieved by including an @ Page directive with an EnableViewStateMac="true" attribute in each ASPX file that has to be protected. Another way is to include the <pages enableViewStateMac="true" /> statement in the Web.config file.
Can the view state be encrypted?

The view state can be encrypted by setting EnableViewStateMac to true and either modifying the <machineKey> element in Machine.config to <machineKey validation="3DES” /> or by adding the above statement to Web.config.
When during the page processing cycle is ViewState available?

The view state is available after the Init() and before the Render() methods are called during Page load.