Interview Questions C#
Interview Questions C#
(There are some mistakes I made in the interview. I don't want you to do the same :) )
1. Please ensure that you are maintaining eye contact with the interviewer.
2. Be confident of what you say. Don't change your answer if the interviewer tries to
make you do so.
3. Please avoid the unwanted examples.
4. Please never use any other technical terms that may provoke the interviewer into
asking questions about.
5. If you don't know the answer, please say "I don't know". It is always better to say so
instead of going with the wrong answer.
Secondly when I was out from college I want to be a software developer because I love
coding/programming. But in this company they are giving me designation of assistant of
project manager i.e. I am going to manage a team not to coding full time. So to be a successful
software developer I decided to leave this company.
I did my BCA from CCS university having 67% from Mewar Institute of Management.
I did my 12th from CBSE Board with 60% & 10th from CBSE Board with 67%.
I like computer, Because In my schooling days, I have scored High marks in that subject
compared to Maths, physics.
My main role is coding, unit testing, bug fixing and maintenance. My team size is 7".
My Project Exam Management & Result Processing System has ADO.NET and ASP.NET
Technology. It includes Crystal Reports and RDLC Reports. My project is based on 2-tier
architecture.
Two-Tier Architecture:
The two-tier is based on Client Server architecture. The two-tier architecture is like client
server application. The direct communication takes place between client and server. There is
no intermediate between client and server. Because of tight coupling a 2 tiered application
will run faster.
Two-Tier Architecture
The above figure shows the architecture of two-tier. Here the direct communication between
client and server, there is no intermediate between client and server.
Let’s take a look of real life example of Railway Reservation two-tier architecture:
Let’s consider that first Person is making Railway Reservation for Mumbai to Delhi by Mumbai
Express at Counter No. 1 and at same time second Person is also try to make Railway
reservation of Mumbai to Delhi from Counter No. 2
If staff from Counter No. 1 is searching for availability into system & at the same staff from
Counter No. 2 is also looking for availability of ticket for same day then in this case there is
might be good change of confusion and chaos occurs. There might be chance of lock the
Railway reservation that reserves the first.
But reservations can be making anywhere from the India, then how it is handled?
So here if there is difference of micro seconds for making reservation by staff from Counter
No. 1 & 2 then second request is added into queue. So in this case the Staff is entering data to
Client Application and reservation request is sent to the database. The database sends back
the information/data to the client.
In this application the Staff user is an end user who is using Railway reservation application
software. He gives inputs to the application software and it sends requests to Server. So here
both Database and Server are incorporated with each other, so this technology is called as
“Client-Server Technology“.
The Two-tier architecture is divided into two parts:
1) Client Application (Client Tier)
2) Database (Data Tier)
On client application side the code is written for saving the data in the SQL server
database. Client sends the request to server and it process the request & send back with data.
The main problem of two tier architecture is the server cannot respond multiple request same
time, as a result it cause a data integrity issue.
Advantages:
1. Easy to maintain and modification is bit easy
2. Communication is faster
Disadvantages:
1. In two tier architecture application performance will be degrade upon increasing the
users.
2. Cost-ineffective
Three-Tier Architecture:
Three-tier architecture typically comprise a presentation tier, a business or data access tier,
and a data tier. Three layers in the three tier architecture are as follows:
1) Client layer
2) Business layer
3) Data layer
1) Client layer:
It is also called as Presentation layer which contains UI part of our application. This layer is
used for the design purpose where data is presented to the user or input is taken from the
user. For example designing registration form which contains text box, label, button etc.
2) Business layer:
In this layer all business logic written like validation of data, calculations, data insertion etc.
This acts as a interface between Client layer and Data Access Layer. This layer is also called
the intermediary layer helps to make communication faster between client and data layer.
3) Data layer:
In this layer actual database is comes in the picture. Data Access Layer contains methods to
connect with database and to perform insert, update, delete, get data from database based on
our input data.
Three-tier Architecture
Advantages
1. High performance, lightweight persistent objects
2. Scalability – Each tier can scale horizontally
3. Performance – Because the Presentation tier can cache requests, network utilization is
minimized, and the load is reduced on the Application and Data tiers.
4. High degree of flexibility in deployment platform and configuration
5. Better Re-use
6. Improve Data Integrity
7. Improved Security – Client is not direct access to database.
8. Easy to maintain and modification is bit easy, won’t affect other modules
9. In three tier architecture application performance is good.
Disadvantages
1. Increase Complexity/Effort
Q. What is the employee size in your company? You don't need to be accurate. You can provide
the approximate value.
A. 20 to 30.
Q. Write an algorithm and program to determine whether or not a word is a palindrome.
using System;
1. using System.Collections.Generic;
2. using System.Linq;
3. using System.Text;
4.
5. namespace FindCountCharOccurance
6. {
7. class Program
8. {
9. static void Main(string[] args)
10. {
11. string strOccur,strChar = null;
12. Console.WriteLine("Enter the string in which you need to find the count of a char
occurance");
13. strOccur = Console.ReadLine();
14.
15. Console.WriteLine("Enter the char to be searched..");
16. strChar = Console.ReadLine();
17. int intCnt =strOccur.Length- strOccur.Replace(strChar, string.Empty).Length;
18. Console.WriteLine("Count of occurance is "+intCnt);
19. Console.ReadLine();
20. }
21. }
22. }
Even though you are creating an object of the derived class, it will invoke the base class first.
Q. Write the output of the following program.
1. class Program
2. {
3. static void Main(string[] args)
4. {
5. B bObj= new B(2);
6. Console.ReadLine();
7.
8. }
9. }
10. public class A
11. {
12. public A()
13. {
14. Console.WriteLine("Hi you are in class A");
15. }
16.
17. public A(int x)
18. {
19.
20. }
21. }
22.
23. public class B:A
24. {
25. public B()
26. {
27. Console.WriteLine("Hi you are in class B");
28. }
29. }
It will throw a compilation error.
B does not contain a constructor that takes 1 argument. If you want to make this program run,
you must create a parameterized constructor for class B also.
Q. Abstract and interface real time examples
Do you mean real-world as in "A live software system which includes Abstract classes or
interfaces" or do you mean "A contrived example which demonstrates their usefullness"?
If you mean the latter think of Vehicle as an abstract class. You can't yet do anything with it
because you have no idea what it does, or how to drive it.
abstract class Vehicle{}
Vehicles could be split into morotized and pedal-powered, but still this is abstract, we still
dont know what to do with it.
abstract class MotorVehicle : Vehicle {}
abstract class PedaledVehicle : Vehicle {}
You could now define a concrete (non-abstract) class, like car.
class MotorCar : MotorVehicle {}
Intefaces come in handy you can only inherit from one base class. So imagine some vehicles
are drivable, others are remote controlled, some vehicles use a stearing wheel, others dont
interface IDrivable{}
interface IHasStearingWheel{}
Now you could derive a DrivableMotorCar from its base clas, and also implement other
behaviours.
class DrivableMotorCar : MotorVehicle, IDrivable, IHasStearingWheel {}
Q. Describe authentication, types, differences?
Basically we can create only one clustered index, but there is a way to have more
1. alert('5' + 5 + 5);
2. alert(5 + 5 + '5');
3. alert(5 + '5' + '5');
4. alert(5 + '5' );
Q. What is ADO.NET
Ans. ADO. NET is a technology or as a set of classes in framework that can be used to interact
with data sources like Database and XML Files or such files where we can kept data in tabular
format. This data can be consumed in any .NET application.
ADO.NET i.e. Microsoft ActiveX Data Objects.
By using ADO.NET we can connect a database, execute commands and retrieve data.
Q. What is Inheritence
Ans. Inheritance, together with encapsulation and polymorphism, is one of the three primary
characteristics (or pillars) of object-oriented programming. Inheritance enables you to create
new classes that reuse, extend, and modify the behavior that is defined in other classes. The
class whose members are inherited is called the base class, and the class that inherits those
members is called the derived class. A derived class can have only one direct base class.
However, inheritance is transitive. If ClassC is derived from ClassB, and ClassB is derived from
ClassA, ClassC inherits the members declared in ClassB and ClassA.
Note
Structs do not support inheritance, but they can implement interfaces.
Conceptually, a derived class is a specialization of the base class. For example, if you have a base
class Animal, you might have one derived class that is named Mammal and another derived
class that is named Reptile. A Mammal is an Animal, and a Reptile is an Animal, but each
derived class represents different specializations of the base class.
When you define a class to derive from another class, the derived class implicitly gains all the
members of the base class, except for its constructors and destructors. The derived class can
thereby reuse the code in the base class without having to re-implement it. In the derived
class, you can add more members. In this manner, the derived class extends the functionality
of the base class.
Example
// WorkItem implicitly inherits from the Object class.
public class WorkItem
{
// Static field currentID stores the job ID of the last WorkItem that
// has been created.
private static int currentID;
//Properties.
protected int ID { get; set; }
protected string Title { get; set; }
protected string Description { get; set; }
protected TimeSpan jobLength { get; set; }
// Method Update enables you to update the title and job length of an
// existing WorkItem object.
public void Update(string title, TimeSpan joblen)
{
this.Title = title;
this.jobLength = joblen;
}
class Program
{
static void Main()
{
// Create an instance of WorkItem by using the constructor in the
// base class that takes three arguments.
WorkItem item = new WorkItem("Fix Bugs",
"Fix all bugs in my code branch",
new TimeSpan(3, 4, 0, 0));
Q.
Q. What is interface
Ans. An interface is a reference type that is somewhat similar to an abstract base class that
consists of only abstract members. When a class implements an interface, it must provide an
implementation for all the members of the interface. A class can implement multiple
interfaces even though it can derive from only a single direct base class.
Interfaces are used to define specific capabilities for classes that do not necessarily have an "is
a" relationship. For example, the System.IEquatable<T> interface can be implemented by any
class or struct that has to enable client code to determine whether two objects of the type are
equivalent (however the type defines equivalence). IEquatable<T> does not imply the same
kind of "is a" relationship that exists between a base class and a derived class (for example, a
Mammal is an Animal).
Q. What is indexing ?
Ans. Indexing means numbering of data where data is arranged by SQL Server in the form of
extents and pages. Each extent is of size 64 KB, having 8 pages of 8KB sizes. An extent may
have data from multiple or same table, but each page holds data from a single table only.
Logically, data is stored in record sets in the table. We have fields (columns) identifying the
type of data contained in each of the record sets. A table is nothing but a collection of record
sets; by default, rows are stored in the form of heaps unless a clustered index has been
defined on the table, in which case, record sets are sorted and stored on the clustered index.
The heaps structure is a simple arrangement where the inserted record is stored in the next
available space on the table page.
There are two types of indexs in Sql Server
1. Clustered Index
2. Non Clustered Index
But everything comes at a cost; the price we pay for having an index on the table is, each time
there is an Insert/Update/Delete, SQL Server updates the active indexes on the table where
these DML are operated. Hence simply creating indexes madly for the sake of better data
retrieval will not serve the purpose. If there are 20 indexes on a table, each time a DML is
done on the table, all these 20 indexes shall be updated so that they can uniquely figure out
the location of the record.
Clustered Index : A clustered index is something that reorganizes the way records in the table
are physically stored. Therefore a table can have only one clustered index. The leaf nodes of a
clustered index contain the data pages, by which I mean the key-value pair in the clustered
index has the index key and the actual data value. Also remember, a clustered index will be
created on a table by default the moment a primary key is created on the table. A clustered
index is something like your train ticket B4/24, you know that you need to board coach B4
and sit on seat number 24. So this index physically leads you to your actual seat.
CREATE CLUSTERED INDEX CL_ID ON SALES(ID);
Non Clustered Index : A non-clustered index is a special type of index in which the logical
order of the index does not match the physical stored order of the rows on disk. The leaf node
of a non-clustered index does not consist of the data pages but a pointer to it. That goes to say
that a non-clustered index can’t survive on its own - it needs a base to live on. A non-clustered
index uses a clustered index (if defined) or the heap to build itself.
When a non-clustered index uses the heap, the leaf node (or the pointer) is a physical location
of the data. When it uses a clustered index, the leaf node (or the pointer) is the clustered index
key value and this key value in turn points to the actual data.
CREATE NONCLUSTERED INDEX NONCI_PC ON SALES(ProductCode);
In an interview, I was asked: Once we declare a primary key, a clustered index is created on the
column by default; what if I wish to create a clustered index and a primary key on two different
columns? Is it possible?
It is very much possible to have two different columns as primary key and clustered indexes.
But remember, if I create a Primary Key on a table first, a CI will also be created. Now, in case I
need them on two different columns, drop the Primary Key constraint and the CI shall
automatically vanish. Now create a CI on column A and declare column B as Primary Key, and
column B will have a NCI created by default on it instead of a CI. This way, we can have two
columns as Primary Key and CI declared on them.
Q. What is a stored procedure ?
Ans. A stored procedure is a compiled set of Transact-SQL statements.
The business logic can be encapsulated using stored procedure.
It improves network traffic by running set of Transact-SQL statements at one go.
Stored procedure is a set of SQL commands that have been complied and stored on the
database sever. They can be used in the code as and when required since hey stored. They
need not be complied over and over again. They can be invoked by CALL procedure (..) or
EXECUTE procedure(..)
Q. Define extended Stored Procedures.
An extended stored procedure compiles as DLL and are created to expand capabilties of
user defined stored procedure. It uses xp_ prefix as naming convention.
Q. What are the purposes and advantages stored procedure?
Answer
Purposes and advantages of stored procedures:
Manage, control and validate data
It can also be used for access mechanisms
Large queries can be avoided
Reduces network traffic since they need not be recompiled
Even though the stored procedure itself may be a complex piece of code, we need
not write it over and over again. Hence stored procedures increases reusability
of code
Permissions can be granted for stored procedures. Hence, increases security.
Determine when to use stored procedure to complete SQL Server tasks.
Answer
If a large piece of code needs to be performed repeatedly, stored procedures are
ideal
When hundreds of lines of SQL code need to be sent; it is better to use stored
procedure through a single statement that executes the code in a procedure,
rather than by sending hundreds of lines of code over the network.
When security is required.
Stored Procedre:
Stored Procedure is a group of sql statements that has been created once and stored in
server database. It’s pre-compile objects which are compiled for first time and its
compiled format is saved which executes (compiled code) whenever it is called. Stored
procedures will accept input parameters so that single stored procedure can be used
over network by multiple clients using different input data. Stored procedures will
reduce network traffic and increase the performance. (Read more Here)
Function:
Function is not pre-compiled object it will execute every time whenever it was called.
Difference between Stored Procedure and Function
1) Procedure can return zero or n values whereas function can return one value which
is mandatory (Read more Here).
2) Procedures can have input, output parameters for it whereas functions can have
only input parameters.
3) Procedure allows select as well as DML(INSERT/UPDATE/DELETE) statements in it
whereas function allows only select statement in it.
4) Functions can be called from procedure whereas procedures cannot be called from
function.
5) Exception can be handled by try-catch block in a procedure whereas try-catch block
cannot be used in a function.
6) We can go for transaction management in procedure whereas we can't go in
function.
7) Procedures cannot be utilized in a select statement whereas function can be
embedded in a select statement.
1.What is GAC ??
2.What is Assembly?
3.How to place DLL in GAC??
4.What is pobm with DLL??
5.What is appSettings ??in webconfig>
6.What is tag in webconfig?
7.Property?.when Master page loads in Which Event?User Control and custom control ??
8.Why interface??
9.what is ajax?how it works with example
10.validate textbox with email using jquery
11.what is Delegate???why ??example.realtime
12.Diffrence between datareader and dataset??
13.which function for execution of query?in .net
14.how many tables can be in Dataset?
15.Main class in dot net ?which contains all clasees.
16 In Ajax will page redirect ??will it go to server for procees?
In Server.Transfer page processing transfers from one page to the other page without making
a round-trip back to the client’s browser. This provides a faster response with a little less
overhead on the server. The clients url history list or current url Server does not update in
case of Server.Transfer.
Response.Redirect is used to redirect the user’s browser to another page or site. It performs
trip back to the client where the client’s browser is redirected to the new page. The user’s
browser history list is updated to reflect the new address.
Q. Pillar of OOPS
Ans. 1 Pillars of Object Oriented Programming
2 Major Pillars
o 2.1 1 Abstraction
o 2.2 2 Encapsulation
o 2.3 3 Modularity
o 2.4 4 Hierarchy
o 2.5 Polymorphism
3 Minor Pillars
o 3.1 1 Concurrency
o 3.2 2 Persistence
The features which make the language ‘Object Oriented Language’, are called the Pillars of Object
Oriented Programming.
Major Pillars
1 Abstraction
Getting only essential things and hiding unnecessary details is called abstraction.
It is the public access region of the class.
Generally, it declares the operations that can be invoked by the clients on object of
class.
Avoid using data members in public region of class, as it may be directly changes by the
client.
Example of Abstraction in c++
2 Encapsulation
Binding of data and code together is called encapsulation.
Encapsulation maintains integrity of object.
For example, the Man class has a walk() method. The code for the Walk() method
defines exactly how a walk happens.
The encapsulation is most often achieved through information hiding.
Information hiding is the process of hiding all the secrets of an object that do not
contribute to its essential characteristics; typically,structure of an object is hidden, as
well as implementation of its methods.
3 Modularity
The act of portioning a program into individual components can reduce its complexity
to some degree.
Modularity can be physical modularity(e.g. divide program into .h, .cpp, .rc files) or
logical modularity(e.g. namespace)
Modularization consists of dividing program into modules that can be compiled
seperately, but which are interconnected.
Modularity helps in easier maintenance of a complex software.
4 Hierarchy
Acquiring all the properties(data members) and behaviors of one class by another class is called
inheritance.
Class Diagram-Inheritance
2. Composition (has-a relationship):
Class Diagram-Composition
Class Diagram-Aggregation
Class Diagram-Association
Polymorphism
Types of polymorphism:
Minor Pillars
1 Concurrency
The concurrency problem arises when multiple threads simultaneously access same
object.
We may use a class library for providing threading support.
We may use interrupts to give illusion of concurrency which need hardware details.
You need to take care of object synchronization when concurrency is introduced in the
system.
2 Persistence
It is property by which object maintains its state across time and space.
The concept gives rise to the concept of object oriented database.
It talks about concept of serialization and also about transferring object across
network.