Showing posts with label C-Sharp-Interview. Show all posts
Showing posts with label C-Sharp-Interview. Show all posts

C# Interview Questions Answers Collection

12/08/2012 No Comment

C# Interview Questions and Answers on Important Topics

C# Assembly Interview Questions

C# Questions on Exception Handling

C# Events and Delegates, Debugging Questions

C# Structure ,Classs and Interface

C# Job Interview Questions with Answers

C# Frequently Asked Questions Answers

C# Basics

C# Programs, Practical Examples and Solutions

C# Implementation based Interview Questions

12/03/2012 No Comment

Some Implementation based questions collected from job interviews.

  1. Explain what is a partial class in C#?
  2. Explain what is the difference when passing by ref in a method and without ref in C#?
  3. How do you fire an event safely?
  4. Explain how do you read an XML with unknown structure?
  5. What is the equivalent JVM in C#?
  6. Explain what is the pattern to enumerate two lists at the same time, without index?
  7. Why use a GlobalClass? What are they for?
  8. How do you apply tracefilters and sourcefilters in an application
  9. How do you read and parse an XML file in C#?
  10. How to create a registry entry from a C# application?
  11. What is a PDB file in C#?
  12. Explain what is the difference between type-safe and strongly typed language?
  13. How do you assign a sql record value to string in asp.net?
  14. How do you read and write a binary file in C#?
  15. How to create a string from bits?
  16. Explain what is a predicate in c#?
  17. What is the different between C# and .Net?
  18. How do you get the HTTP Status Code?
  19. How do you assign a static method to a delegate in C# via reflection
  20. How do you Read back the results of a committed transaction in C#?
  21. How to create an array in a for loop?
  22. How do you dynamically reference incremented properties in C#?
  23. What is a private interface in C#?
  24. What is the difference between the | and || or operators?
  25. How do you read data that is waiting to be read from a device?
  26. How to create instance of inherited in static base method in C#?
  27. Explain what is the is a public key token and how is it calculated in assembly strong names?
  28. What is the difference between TotalFreeSpace and AvailableFreeSpace
  29. How do you sort the columns in a datagrid into alphabetical order?
  30. How do you read from all files in a given folder?
  31. What is a serializable object in C#?
  32. What is the difference between return and return () in c#
  33. What is the difference between Control.Focus() and Control.Select()
  34. How do you force a task cancellation?
  35. How do you read keyboard input on a Winform?
  36. How to create setup for any exe?
  37. What is the DLR Layer Responsibility?
  38. What is the difference between Control.Focus() and Control.Select()
  39. How do you auto-map name value collection to a strongly typed class?
  40. How to create your own System namespace and objects?
  41. What is a String[*] and how do you cast it?
  42. How do you automatically login to another page from a Silverlight application?
  43. How do you automatically run an application when the system starts?

Wipro C# Interview Questions for Architects

11/27/2012 No Comment

 Wipro C#.NET Interview Questions for Senior Professionals.

Dear readers. We request you to use the comment section for answers and suggestions.
  1. How do you make one form load before the other in C#?
  2. How do you bind a list to a ddl?
  3. What is an elegant way to aggregate properties from subclasses in C#?
  4. How do you refresh a form in c#?
  5. How do you reduce interface lag in C#?
  6. Explain what is an execution frame?
  7. What is the equivalent of VB's "Dim" statement in C#?
  8. How do you bind a simple array?
  9. How to determine if a decimal/double is an integer?
  10. Explain what is an Extension Class?
  11. How do you show a taskbar notification in your C# application?
  12. How do you get a a list of files from a web directory?
  13. What event to catch UserControl disposed of?
  14. What is an internal sealed class in C#?
  15. What is the best way to implement input restrictions on a TextBox in C#?
  16. What is an unified type system in C#?
  17. Explain what is the extern keyword and usage in C#
  18. How do you bind to a property in C$?
  19. How do you get a C# property name as a string with reflection?
  20. How do you reference a specific class type in C#?
  21. How to determine if source is compiled successfully
  22. What is AppDomain?
  23. What is the fastest collection in c# to implement a prioritizing queue?
  24. How do you connect to a local Socket in C#?
  25. What is Application Domain in .NET and what is its need?
  26. Explain what is AsyncCallback in C#?
  27. Explain what is the flow of MVP pattern in C#?
  28. How do you refund a transaction in Authorize.net?
  29. What is the function of the "this" keyword in a constructor?
  30. How do you set the namespace URI in c#?
  31. How do you get a list of all currently loaded assemblies?
  32. What is best practice naming for private methods?
  33. What is the function of the ~ operator?
  34. Explain how do you get a list of available tables from an ODBC connection?
  35. How to display the current time and date in C#
  36. Explain how do you localize password validation in C#?

IBM C# Interview Questions

11/20/2012 No Comment

Collection of Advanced C# and .NET Interview Questions for senior level developers asked in IBM and HP.

  1. Explain how do you round a decimal value to 2 decimal places (for output on a page)
  2. What is EntityReference?
  3. How do you round a float up to the nearest int in C#?
  4. How do you change the application language in ASP.NET?
  5. How do you round a number to two decimal places in C#?
  6. What is equivalent to Microsoft.VisualBasic.Collection in C#?
  7. What is the use of OR operator in an IF statement?
  8. How do you run a query that makes table in Access through C#?
  9. How do start/stop services using net stop command in C#
  10. What is the order of Dictionary.Values.ToArray()?
  11. Explain how do you change the color of an Image?
  12. Explain how do you run a simple bit of code in a new thread?
  13. How to do document sharing in asp.net?
  14. What is events in c#?
  15. What is the original location for asp.net request in C#.NET?
  16. C# Production Server, do you collect the garbage collection?
  17. How do you run multiple WCF services on one port?
  18. Explain how do you do encoding on string or char?
  19. How do you set a property to a default value in C#?
  20. Explain how do you get the computer name in .NET
  21. How do you run nGen at the end of the installation (MSI)?
  22. How to do event driven programming in C#.NET?
  23. Explain what is functional testing?
  24. How do you change the full background color of the console window in C#?
  25. Explain how do you run nGen at the end of the installation (MSI)?

HCL C# Interview Questions for Senior Developers

11/07/2012 No Comment

Advanced C# Interview Questions asked in HCL for Senior Developers.

  1. What does new() mean in C#?
  2. What's the difference between a public constructor in an internal class and an internal constructor?
  3. How do static constructors for generic types work?
  4. How to store a ratio in a single variable and read it back in C#
  5. What does object @object mean in C#?
  6. What's the difference between a streamwriter and a binarywriter?
  7. How do static properties work in an asp.net enviroment?
  8. How do you mock a private field?
  9. How to store the file in a string?
  10. What does object.start() mean?
  11. What is the difference between Fixed and Unsafe?
  12. How do StyleTriggers work?
  13. How to suspend a thread by its name from the main thread?
  14. What does placing a @ in front of a C# variable name do?
  15. What's the difference between an abstract class and a static one?
  16. How do you use random numbers in C#?
  17. How to tell what value types are initialized to by the CLR?
  18. What is the difference between Function and Delegate in C#?
  19. How do you display HTML in windows app in C#?
  20. What does really happen when you do GetType()?
  21. What's the difference between an argument and a parameter?
  22. How do the compiler know it is out of scope?
  23. What is the difference between HashSet and List in C#?
  24. How do you mock your Webservice?
  25. How do you use SecureString securely?
  26. How do you model c# attributes in UML?
  27. How do transactions work in nhibernate?
  28. How do you use System.Threading.Timer and Thread.Sleep?
  29. How to track directory opening?
  30. What does RETURN in a method do?
  31. How do virtual methods work in C#?

Accenture C# Interview Questions for Avanced Developers

11/04/2012 1 Comment

Accenture C#.NET Interview Questions. 

Dear readers. Please use the comment section for the answers.
  1. What is real purpose of isolated storage in .Net?
  2. How do you combine two bytes from network order into a usual short?
  3. How do you get your C# program to sleep for 50 msec?
  4. What is reflection and what can it be used for in C#.NET?
  5. What is the simplest way to initialize an Array of N numbers following a simple pattern?
  6. How do you combine two Expressions in C#?
  7. How do you GetCustomAttributes in C#?
  8. What is relation between GC, Finalize() and Dispose?
  9. How do you communicate between multiple threads?
  10. How do you give a C# Auto-Property a default value?
  11. How do you do transaction control on data access using DataAdapter and Stored Procedure in C#?
  12. What is relationship between CTS and CLS?
  13. How do you compare a byte[] to a string?
  14. How can you compare a generic type to its default value?
  15. How do you grab the first letter in a string?
  16. How to do unit test on remote store procedure
  17. What is the switch command in C#?
  18. How do you compare two AssemblyName instances?
  19. How do you set a DateTimePicker to be read only?
  20. What is the syntax to declare an event in C#?
  21. How do you check if a List contains an object of a certain type?
  22. How can you compare two datatables?
  23. How can you do validations for numeric,double and empty values for datagridview?
  24. How do you completely turn off cookies in ASP.net?
  25. How can you group in memory lists?
  26. How do you set a field value in an C# Expression tree?
  27. How to do vertical and horizontal scrolling in treeview?
  28. What is the thinking behind having foreach cast to the variable type?
  29. How do you compose existing Linq Expressions?
  30. What is rule-based algorithm?
  31. What is the type of null literal?
  32. Could someone explain to me what exactly is an event and what is the difference with delegate?
  33. How do you concatenate 2 bytes?
  34. How do you set a static bool in another app domain?

Toughest C# Interview Questions

9/21/2012 2 Comments

Advanced C# Interview Questions expected for senior professionals in companies like Wipro, Infosys, TCS, IBM.

  1. How do you read the eventlog of windows service?
  2. In C#: how do you subtract two dates?
  3. What is the easiest way to serialize and deserialize to XML?
  4. How can I do Databinding in c#?
  5. How can you read the filenames inside the directory to an array?
  6. How to define a Method with no return in C#?
  7. How do you avoid a race condition when using Dispatcher.Run()?
  8. How to define a property whose type in database is bit?
  9. How can you check if a printer is installed and ready using C#?
  10. How do you generate a line chart from an asp.net WebService?
  11. How to define a variable that can be used everywhere?
  12. How do you create a banner panel in C#?
  13. How can you avoid an infinite loop when overriding a virtual property?
  14. How do you Read the value of an attribute in a Method
  15. What is an "endpoint" in WCF?
  16. How can you double buffer a Panel in C#?
  17. How do you avoid the loader lock?
  18. How to define two dependent generic interfaces?
  19. Explain what is the equivalent datatype of SQL Server's Numeric in C#
  20. How do you reconcile IDisposable and IoC?
  21. How do you generate One time passwords (OTP / HOTP)?
  22. Explain what is an abstract type in C#?
  23. How do you redirect to a website using MVC?
  24. Explain how can you delete from registry - in C#?
  25. How do you handle non existing nodes in Linq / XML?
  26. What is the equivalent of JPA in .NET?
  27. How do you make custom controls in C#?
  28. How do you bind a field to a control in WinForms?
  29. How do you redirect to another page with ASP.NET?
Dear Readers, please use the comment section for the answers.

C# Senior Position Interview Questions.

8/20/2012 No Comment

C# Senior Position Interview Questions for IT companies.

Dear Readers, we kindly request you to provide answers in the comment section. Thank you.

  1. What is HTTP Referrer header in C#?
  2. What is the proper use of keyword 'this' in private class members?
  3. How do you do logging in C#? Can you explain in brief.
  4. What is the proper way of importing a form in C#?
  5. How do you get an IP address, from a TcpClient?
  6. How to do lookups using a list of string?
  7. What is the proper way to access a value internally?
  8. What is a binary null character in C#.NET?
  9. How do you get the exact time for a remote server in C#
  10. How can you save data in Silverlight C#?
  11. How do you make a subscription dependent on another subscription?
  12. What is the proper way to check for and handle null return values?
  13. How do you do simple math, with rounding, on integers?
  14. Explain how can you change the type of an enum?
  15. How can you get the first element from an IEnumerable in .net?
  16. How to do multiple Upload/Download in a single connection in FTP using C#
  17. What is interface casting for in C#?
  18. What is the proper way to handle an array of one class in another class?
  19. What is internal set property in c#?
  20. How do you get the host machine's primary IP address?
  21. How can you save your query to a datatable?
  22. How to do NHibernate queries with reference as criterion?
  23. What is the purpose for a relation in a dataset?
  24. How do you get the inner arrays length in a second array in C#?
  25. How do you deserialize into an existing object
  26. What is the purpose of "protected internal" scope
  27. How do you declare a base class as being private?

C# Tough Interview Questions collected from Interviews

8/12/2012 No Comment

C# Tough Interview Questions collected from Interviews in companies - Wipro, Accenture, IBM.

Dear Readers, please contribute with the answers in the comment section. We will update your answers with a new post.
  1. How to do Exception Handling & Tracing in C#?
  2. How do you handle a socket in C#.NET?
  3. How can you get the current date in C#?
  4. Explain how do you run processes synchronously, targeting the same output?
  5. How can you programmatically identify the number of references to a method with C#.NET?
  6. What do you mean by generics in C#?
  7. Explain what is the point of a constant in C#.NET?
  8. How do you get the current directory in a web service?
  9. How do you create an instance from a string in C#?
  10. What do you mean by generics, describe its uses and application?
  11. Explain ow can you intercept a method call in C#?
  12. What do you mean by global.asax and what it is used for?
  13. What is the point of the ISerializable interface?
  14. How can you get the current screen cursor position?
  15. Explain how can you run your code without having the page refresh in C#?
  16. Explain the process of grouping in LINQ
  17. How can you retrieve attributes on properties in C#?
  18. What do you mean by Globalization and Localization?
  19. Explain what is the point of using SET?
  20. How will you change the output in the debugger for a class in C#?
  21. What’s the difference between System.Type and System.RuntimeType in C#?
  22. How can you get the current time of day?
  23. Explain how can you do join in ADO.NET Entity Framework
  24. Reflection in C#: How do you get the calling method name and type?
  25. What is good practice when deciding where Enums and structs should be defined?
  26. How do you change the Read-only file attribute for each file in a folder using c#?
  27. What is the process of building/installing a service?
  28. How can you programmatically invoke an event?
  29. Explain how to do localization without resource file?

Cap Gemini C# Interview Qestions for Senior MS.NET Consultants

7/16/2012 No Comment

Cap Gemini Senior Level C# Interview Questions.

Please use the comment section to answer the questions.

  1. Can you tell me another way to close the application other than Application.Exit()?
  2. How can you convert an Enum to a list in C#?
  3. What is this "Log" class in C#.NET?
  4. How do you shutdown the computer in C#.NET?
  5. What Application.Run( ) does?
  6. What is the appropriate C# manner to read argument/parameters in Console applications?
  7. Do pointers exist in .NET?
  8. How do you sign variables in C#.NET?
  9. What do you mean by anonymous methods in C#?
  10. Do session use cookies in C#.NET?
  11. How can you convert an integer to two bytes in C#?
  12. How do you implement an abstract event or interface method event in C#?
  13. How can you find no of duplicate values in an arraylist?
  14. What do you mean by anonymous types in C#?
  15. What is the automatic variable name of an auto-implemented properties
  16. How do you implement an ASP.NET role provider?
  17. Explain how can you simulate a serial device?
  18. How to find the Mode in Array C#?
  19. Do WCF Services expose Properties?
  20. Explain how do you implement asynchronous caching?
  21. How do you simulate Typing in C#?
  22. Explain how to find the size of a class in C#
  23. Do you have access to the variables in C# when using get and set?
  24. How do you implement authentication in servicestack.net
  25. What do you mean by 'closures' in C#?
  26. What is the benefit of using namespace aliases in C#?
  27. Is there a need to set initial values in your class constructor?
  28. Explain how do you convert byte to string?
  29. How do you softcode a workflow activity in .NET?

Infosys C# Interview Questions for Architects and Designers

7/08/2012 No Comment

Infosys C# Interview Questions for senior professionals and Designers. 

Please use the comment section to answer the questions.

  1. Explain what is the use of labels in C#?
  2. Explain what is the difference between AJAX POST and GET
  3. How do you convert a DateTime to a Date in C#
  4. Explain how can you hide encapsulation in C#?
  5. What is the difference between read and readline in C#?
  6. Explain what is the difference between Char.IsDigit() and Char.IsNumber() in C#
  7. What is the use of the 'this' keyword, and what is the reason why?
  8. Explain what is the difference in volatile in C# and C.
  9. How can you set up an ASP.NET build server?
  10. How do you send POST variables with c#?
  11. What is the use of web.config, web.config.debug, web.config.release?
  12. Explain what is the difference of using int and uint and when to use
  13. How can you identify a default constructor in  C#?
  14. What is the ~ character used for in C#
  15. How do you identify authentcated user in WCF?
  16. How can you setup a nested/chained function within a C# Class
  17. How to extract only server names in C#
  18. Explain what are the different ways of type-conversion. What is the difference between them?
  19. What is the Advantage of DLR in C#.NET 4?
  20. How do you convert a TimeSpan to a formatted string?
  21. What is the advantage of using Interface?
  22. What is the yield keyword used for in C#?
  23. How to find a reference datatype in C#.NET?
  24. How can you implement a generic stack in C#?
  25. How can you share Business Layer classes between a desktop App and a Web App in c#?

Advanced C# Interview Questions

7/04/2012 No Comment

Tough C# Interview Questions expected for a senior .NET developer.

Please use the comment section to answer the questions.

  1. Explain how do you get the return type of a delegate type through reflection in C#?
  2. How to do you do internationalization in XAML?
  3. What is managed and unmanaged code in C#?
  4. What is the Purpose of exceptions?
  5. Explain how do you check if one of two values is TRUE?
  6. How can you select a desired row in a grouped result using c# LINQ
  7. How to do some performance testing in asp.net mvc?
  8. What is the difference between Count and Count() in observable collections in C#?
  9. What is the purpose of IEnumerator in C#?
  10. What do you mean by Connection.Dispose()? in c#.net?
  11. What is the purpose of new() when defining a generic?
  12. How to do string comparison with wildcard pattern in C#?
  13. What is meant by Web Services?
  14. How do you get the SOAP headers as XML in C#?
  15. Explain how to do table of simple data in WinForms?
  16. What is the purpose of return statement in C# programs.
  17. Explain what is Mocking in C#?
  18. What is the difference between Char.IsDigit() vs Char.IsNumber() ?
  19. How do you get the subscribers of an event?
  20. Explain how do you select tokens from a string using LINQ?
  21. How do you sort a C# dictionary by value?
  22. What is the purpose of ’this’ keyword in C#?
  23. Explain how do you document a c# dll ?
  24. How do you chose the most appropriate type of exception to throw?
  25. What is the purpose of ’volatile’ keyword in C#
  26. What is the difference between Method vs Property in C#

TCS C# Interview Questions for Senior .NET Developer

7/04/2012 No Comment

TCS C# Interview Questions for Senior .NET Developer.

Please use the comment section to answer the questions.

  1. How to dynamically set variable value with C#?
  2. What is System.Linq.Expressions in C# used for?
  3. How do you access attributes when de-serializing XML,?
  4. How do you control event firing in C#?
  5. How do you handle upgrades of software you develop?
  6. How to eliminate duplicate code?
  7. What is the use of a static class?
  8. How do you control how an object is hashed by a hashset?
  9. How do you handle user preferences?
  10. What is System.Void in C#? 
  11. How do you emulate "friend" in C#?
  12. Explain what is the use of calling base class's constructor if there is no overloading constructor available?
  13. Using C#, how do you validate a html file?
  14. Explain what is the difference between "var" and "object" in C#
  15. How can you convert a byte array to a string in C#?
  16. How can you have your method wait for all threads to finish?
  17. How do you enter a special character as a password character in C#
  18. What is the use of documented protected properties is in framework classes?
  19. How do you convert a Char into a Keycode in .Net?
  20. How do you have your WPF application to be running as a service in C#?
  21. How to enumerate through IDictionary in C#?
  22. Explain what is the "volatile" keyword used for?
  23. What is the use of IClonable interface in C#.NET?
  24. Explain what is the difference between | and || or & and && for comparison.
  25. What is the use of Indexers in C#?
  26. How do you convert a DataTable into a generic list in C#?

30 Advanced C# Interview Questions for Senior Developers

7/03/2012 No Comment

I am listing some of the Tough C# Interview Questions for Senior .NET Developer positions.

These questions can be expected for higher level positions. Please use the comment section to answer the questions.


  1. What is the function of the ”yield” keyword in C#. What does the C# compiler does internally
  2. Explain what you mean by Dependency Injection / Inversion of Control in C #.
  3. Explain the difference between a BeginInvoke and an Invoke
  4. In C# , what is cyclomatic complexity and explain its significance
  5. Contrast the use of Debug.Write and Trace.Write? When should each be used
  6. Explain the difference between object identity and object equivalence and their use
  7. How would you implement deep copy in .NET?
  8. How many types of memory leaks can happen in a .NET application and how would you troubleshoot a memory leak?
  9. Explain some design patterns – Composite Design Pattern, Decorator Design Pattern, Facade Design Pattern
  10. Explain C#.NET best practices you have implemented in your project.
  11. What is the main difference between Monitor.Wait and Monitor.Pulse
  12. Explain how you would create responsive UI without using threads.
  13. How will you get windows service name from app.config file in C#
  14. Explain how would you programmatically build and compile another C# project from your current project
  15. Using threads how which will receive same data at the same time?
  16. How would you link a C# Windows Form to an internet application?
  17. Explain the importance of the ”PropertySpecified” pattern used by the XmlSerializer. What problem does it solve?
  18. Contrast the difference between Debug and Release build? What is the speed difference you see in both?
  19. What is the difference between Background thread and UI thread in C#
  20. Explain the difference between Activator.CreateInstance and Assembly.CreateInstance
  21. How will you find a foreground thread from a background thread?
  22. Explain how would you build a HttpTraceListener?
  23. How will you remove the blank entry from an array in C#?
  24. Explain the process of loading an assembly from the GAC?
  25. How would you sort through an array of structs?
  26. Explain the process of creating an expression parser in c#?
  27. How would you get a list of installed codecs in C#?
  28. Explain how to architect Entity Framework Application with MEF.
  29. What is the use of this class UnmanagedMemoryStream?
  30. Explain how will you architect a web service cache in c#

C# Interview Question and Answers Collection

10/18/2010 No Comment

Latest C# Interview Question Answers Collection.

Collection of some of the common question expected in a .NET interview.

Is multiple inheritance supported in C#.NET?
In C#.NET, multiple inheritance is not supported, however to accommodate it in a different way you can use interfaces.

Can you tell what is the implicit name of the parameter that gets passed into the class set method?
The implicit name of the parameter is Value, and its datatype depends on whatever variable we would be changing.

Explain in brief how can you inherit from a class in C#.NET? 
You can place a colon and following it the name of the base class. It is double colon in C++ when you inherit.

To inherit a protected class-level variable in C#, where it is made available? 
It is made available to Classes in the same namespace.

Can you tell me if private class-level variables be inherited in C#? 
Technically, private class-level variables can be inherited, but they are not accessible, hence you can say that they are not inherited. 

Explain in brief the accessibility modifier protected internal. 
Protected internal is a accessibility modifier that is madeavailable to derived classes and classes within the same Assembly as also from the C# base class.


Explain in brief how method overriding different from method overloading? 
When you do overriding, you change the method behavior for a derived class. Whereas when you do overloading, it simply involves having a method with the same name within the class.

In C#, what is the top .NET class that everything is derived from? 
The top .NET class is System.Object from which everything is derived.

In C#, what does the keyword virtual mean in the method definition? 
When you use the virtual keyword, it specified that the method can be over-ridden.

In C#, can you override private virtual methods?
We cannot override private virtual methods. Again, you cannot access private methods in inherited classes, it have to be protected in the base class to allow any sort of access.

In C# can you prevent your class from being inherited and becoming a base class for some other classes?
Yes we can prevent it, we use the keyword sealed in the class definition. The developer while he is trying to derive from a class will get a message: cannot inherit from Sealed class WhateverBaseClassName.This concept is analogous to final class in Java.

Explain in brief how can you allow class to be inherited, but prevent the method from being over-ridden? 
We just need to leave the class public and make the method sealed to prevent the method from being overridden.

Explain in brief what is an abstract class in C#.NET?
A class in C# cannot be instantiated. There is a concept in C++  which is known as pure virtual method. A class that must be inherited and have the methods over-ridden. Hence, an abstract class is a blueprint for a class without any implementation.

Under what circumstances you absolutely have to declare a class as abstract?
If there is at least one of the methods in the class which is abstract. In cases when the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.

What do you mean by a interface class in C#?
A interface class is nothing but an abstract class with public abstract methods all of which must be implemented in the inherited classes.

Why you cannot specify the accessibility modifier for methods inside the C# interface? 
They all must be declared public. Hence, you are not allowed to specify any accessibility, it is public by default.

Can you inherit multiple interfaces in C#? What if they have conflicting method names?
Yes, we can inherit multiple inheritance in C#

It depends on the programmer to implement the method inside his own class, so implementation is left entirely up to the coder. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data

Explain in brief what is the difference between an interface and abstract class?
In the interface class, its a  necessary condition that all methods must be abstract; in the abstract class some methods can also be concrete. In the interface class no accessibility modifiers are allowed, whereas in abstract classes, they are allowed.

Can you tell me how can you overload a method?
We can overload by using different parameter data types, different number of parameters, different order of parameters.

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

Differentiate between System.String and System.StringBuilder classes? 
The class System.String is immutable whereas System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed on it.

Explain what is the main advantage of using System.Text.StringBuilder over System.String? 
The main advantage is that StringBuilder is more efficient in cases, where a lot of manipulation is done to the text. We know that Strings are immutable, hence each time it is being operated on, a new instance is created for it.

Can you tell me if we can store multiple data types in System.Array? 
No, we cannot store.

Differentiate between the System.Array.CopyTo() and System.Array.Clone()?
System.Array.CopyTo() is used to perform a deep copy of the array whereas System.Array.Clone() is shallow.

What will you do to sort the elements of the array in descending order? 
To sort the elements in descending order, we have to call Sort() and then Reverse() methods.

Name the .NET datatype that allows the retrieval of data by a unique key? 
The datatype is HashTable.

What is class SortedList underneath? 
A sorted HashTable.

In a structured exception handling, will finally block get executed if the exception had not occurred? Yes, the finally block will always get executed.

What is 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 inside a program be executed?
Multiple catch cannot be executed. 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 not a good practice to throw your own exceptions in C#? 
When 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. When you trow your own exceptions, it signifies some design flaws in the C# project.

What do you mean by a delegate in C#? 
A delegate is nothing but a object encapsulates a reference to a method. In C++ they were referred to as function pointers.

What do you mean by a multicast delegate in C#?

Multicast delegate a delegate that points to and eventually fires off several methods.


Can you tell me how the DLL Hell problem is solved in .NET? 
By using the concept of Assembly versioning which 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.

Tell us the ways to deploy an assembly in C#? 
It can be done in three simple steps - An MSI installer, a CAB archive, and XCOPY command.

What do you mean by a satellite assembly in C#? 
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.

Name the two namespaces that are necessary to create a localized application in C#? 
The tow are System.Globalization and System.Resources.

Differentiate between // comments, /* */ comments and /// comments? 
Single-line, multi-line and XML documentation comments.

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

Can you tell me if XML is case-sensitive or not? 
Yes, so and are different elements.

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.

Can you tell me how do you debug an ASP.NET Web application? 
For debugging a ASP.NET web application you have to attach the aspnet_wp.exe process to the DbgClr debugger.

Name and explain in brief the 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 you can change, if you are debugging via Visual Studio.NET, just go to Immediate window.

Name the three services model (three-tier application). 
The three services model are - 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.

Can you tell me 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 use of the wildcard character in SQL? 
The wildcard character is %, the proper query with LIKE would involve ‘La%’.

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

What are the connections does Microsoft SQL Server use to support? 
MS SQL Server supports Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).

Can you tell me which one is trusted and which one is untrusted connection? 
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.

Under what circumstances would you use a untrusted verificaion? 
Web Services might use it, as well as non-Windows applications.

What is the use of the parameter Initial Catalog defined inside Connection String? 
It specifies the database name to connect to.

Name the data provider that is used to connect to Access database? 
The data provider is Microsoft.Access.

What is the significance of the Dispose method in the connection object? 
The dispose method deletes the object from the memory.

Explain in brief what is a pre-requisite for connection pooling? 
For connection pooling, multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.

C# Realtime Interview Questions and Answers:Part 4

11/07/2009 No Comment
Collection of C#.NET Interview Questions.

What is the use of the main() function in C#?

Every executable C# application must contain a class defining a Main() method that signifies the entry point of the application. Note that the Main() method is of the access type public by nature. Moreover, it is also static. See example below:
using System;
class Question
{
public static int Main(string[] args)
{
Console.Writeline("Another Question");
Console.Readline();
return 0;
}
}
A public member is accessible from other types. The main() method is set as static so that it may be invoked at class level itself, without the need of creating an instance of it. The single parameter is an array of strings. that may contain any number of incoming command line arguments.

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

Can we set different types of parameters & return-types in main() method"?
Yes. The Main() method may easily be played around with by developers by passing different parameters and setting different return types. See the code below, that demonstrates different ways the Main() method may be implemented:

(1)
public static void Main(string[] args)
{
//NO return type, the argument is an array of strings
}
(2)
public static int Main(string[] args)
{
//Return type is int, argument is an array of strings
}
(3)
public static int Main()
{
//Return type is int, NO arguments
}
(4)
public static void Main()
{
//Return type is void, NO arguments
}

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

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

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

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

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

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

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

What are the different parameter modifiers available in C#?

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

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

Explain the main difference between out and ref in C#?
  • The out parameters will return  a compiler error if they are not assigned a value in the method. However, this is not the case with ref parameters in C#
  • The out parameters need not necessarily be initialized before passing to the method, whereas ref parameters always need to have an initial value before they are passed to a method.
  • Ref parameters are for that kind of data that might be modified,  whereas out parameters are for data that's an additional output for the function that are already using the return value for something.

C Sharp Realtime Interview Questions and Answers:Part 3

10/28/2009 No Comment
Interview Questions and Answers for C sharp in companies like IBM,Accenture,Dell,Wipro Infosys,TCS,HP

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

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


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

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

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

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

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

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

How to sort array elements in descending order in C#?

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

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

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

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

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

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

Polymorphism may be achieved by overloading a function, overloading an operator, changing the order of types, changing the types using the same name for the member in context.
Example:
Public Class Calc
{
public void fnMultiply(int x, int y)
{ return x * y; }
public void fnMultiply(int x, int y, int z)
{ return x * y * z; }
}
...
...
Calc obj;
int Result;
Result = obj.fnMultiply(2,3,4); // The second fnMultiply would be called
Result = obj.fnMultiply(3,4); // The first fnMultiply would be called
//Here, the call depends on the number of parameters passed, polymorphism is achieved using overloading

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

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

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

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

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

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

What is function overloading in C#?

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

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

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

How to call a specific base constructor in C#?

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

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

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

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

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

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

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

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

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

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

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

What is a static constructor?

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

Can a class be created without a constructor?
No. In case we dont define the constructor, the class will access the no-argument constructor from its base class. The compiler will make this happen during compilation.

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

C# Realtime Interview Questions and Answers:Part 5

10/22/2009 No Comment

Most common Interview Questions and Answers for C sharp asked in top companies.

C# Questions asked in companies like IBM, Accenture, Dell, Wipro, Infosys, TCS, HP, Cap Gemini, Tech Mahindra, Patni and Birlasoft

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

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

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

I was trying to use an "out int" parameter in one of my functions. How should I declare the variable that I am passing to it?
You should declare the variable as an int, but when you pass it in you must specify it as 'out', like the following:
int i;
foo(out i);
where foo is declared as follows:
[return-type] foo(out int o) { }

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

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

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

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

What is the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception? Does C# support try-catch-finally blocks?
Yes. Try-catch-finally blocks are supported by the C# compiler. Here's an example of a try-catch-finally block:
using System;
public class TryTest
{
static void Main()
{
try
{
Console.WriteLine("In Try block");
throw new ArgumentException();
}
catch(ArgumentException n1)
{
Console.WriteLine("Catch Block");
}
finally
{
Console.WriteLine("Finally Block");
}
}
}
Output: In Try Block
Catch Block
Finally Block

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

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

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

Is there regular expression (regex) support available to C# developers?
Yes. The .NET class libraries provide support for regular expressions. Look at the documentation for the System.Text.RegularExpressions namespace.
Does C# support properties of array types?
Yes. Here's a simple example: using System;
class Class1
{
private string[] MyField;
public string[] MyProperty
{
get { return MyField; }
set { MyField = value; }
}
}
class MainClass
{
public static int Main(string[] args)
{
Class1 c = new Class1();
string[] arr = new string[] {"apple", "banana"};
c.MyProperty = arr;
Console.WriteLine(c.MyProperty[0]); // "apple"
return 0;
}
}

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

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

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

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

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

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

C# Realtime Interview Questions and Answers:Part 2

10/16/2009 No Comment
C#.NET Interview Questions and Realtime Discussions ,C# Realtime Interview Questions,C# Questions for MNCs like Cap Gemini,CTS,HP,Patni,Sasken

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Which method is actually called ultimately when Console.WriteLine( ) is invoked?
A) Append( )
B) AppendFormat( )
C) Tostring( )
Ans: B, AppendFormat() method is called.

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

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

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

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

Private assemblies are the ones which are in your application folder itself. They can be easily and uniquely identified by their name.
These type of assemblies can be deployed simply by copying them to the bin folder of your application.

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

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

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

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

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

 

Aired | The content is copyrighted and may not be reproduced on other websites. | Copyright © 2009-2016 | All Rights Reserved 2016

Contact Us | About Us | Privacy Policy and Disclaimer