Wednesday 8 April 2015

C#.NET INTERVIEW QUESTIONS & ANSWERS



1.  What is object-oriented programming (OOP) Language?

Object-oriented programming (OOP) is a programming language model organized around objects rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.
                It is necessary to understand some of the concepts used extensively in object oriented programming.These include
  • Objects
  • Classes
  • Data abstraction and encapsulation
  • Inheritance
  • Polymorphism
  • Dynamic Binding
  • Message passing.

2. Explain about C# Language.

  • C# is a new object-oriented language from Microsoft that is currently used for application development on the .NET platform.
  • It exhibits features found in languages such as C++, Java, Smalltalk, and Perl, among others.
  • C# has been submitted to the standards body.

3. How does C# differ from C++?

  • C# doesn't support multiple inheritances while C++ does.
  • We can use switch statement with string values in C# while in C++ only Character and integer values supported.
  • Casting is Safer in C# than C++.
  • C# doesn’t require semicolon on completion of class definition while C++ use.
  • In C#, Command line parameter acts differently as compared to C++.

4.  What is a class ?

A class is the generic definition of what an object is. A Class describes all the attributes of the object, as well as the methods that implement the behavior of the member object. In other words, class is a template of an object. For ease of understanding a class, we will look at an example. In the classEmployee given below, Name and Salary are the attributes of the class Person. The Setter and Gettermethods are used to store and fetch data from the variable.

5.  What are namespaces, and how they are used?

  • In .Net framework namespaces are used to manage classes.
  • The Key difference between .Net namespaces and java packages is that namespace doesn’t define the physical layout of source file while java packages do.
  • Namespace define logical structure of the code.
  • Namespaces can be utilized via using keyword, in .net framework, many class have their namespace defined such as System.Net.
  • We can create our own C# source files which can relate to multiple projects.

6. What is the difference between public, static and void?

  • public: Public Modifier in C# is most liberal among all access modifiers, it can access from anywhere inside or outside other class. There is no access restriction in public modifiers .public keyword is used just before the class keyword to declare class as public.
  • static: Static method is used to declare main method global one and we do not need to create instance of that class. We can access methods of static class by using the class name followed by. Operator and method name .The compiler stores Static method’s address and uses this information before any object is created for execution.
  • void: The void modifier tells that the Main method can't return any value
7. feature of C# language?

    Boolean Conditions
    Automatic Garbage Collection
    Standard Library
    Assembly Versioning
    Properties and Events
    Delegates and Events Management
    Easy-to-use Generics
    Indexers
    Conditional Compilation
    Simple Multithreading
    LINQ and Lambda Expressions
    Integration with Windows

8. What is object?

    Objects are created from Classes, in C#, is an instance of a class that is             created dynamically. Object is also a keyword that is an alias for the                 predefined type System.

9. What is Constructors, explain with syntax?

A is special method of the class that will be automatically invoked when an instance of the class is created is called as constructor.

Constructors are mainly used to initialize private fields of the class while creating an instance for the class.

When you are not creating a constructor in the class, then compiler will automatically create a default constructor in the class that initializes all numeric fields in the class to zero and all string and object fields to null.

Syntax.
[Access Modifier] ClassName([Parameters])
{
}

10. Types of Constructors?


Basically constructors are 5 types those are
Default Constructor
Parameterized Constructor
Copy Constructor
Static Constructor
Private Constructor

11. What are the difference between Structure and Class?

  • Structures are Values types while Classes are Reference types.
  • In structure values stored in stack while in class value’s reference stored in heap.
  • In structure direct values is stored while in class reference to a value is stored.
  • Inheritance is supported in classes while structure doesn’t support.
  • We cannot declare destructor in structure whereas in class it is possible.
  • We can’t have explicitly parameter less constructors in structure whereas classes can have.
  • Class can have protected members while structure can’t have.
  • Structure is declared by using struct keyword while class is declared by using Class keyword.
  • Structures don’t have memory management while classes have due to garbage collector.
  • New operator works in classes while not in structure

12. What is Custom Control?

  • A Custom control inherits from System.Windows.Controls.Control class.
  • They are compiled code (Dlls), faster to use, difficult to develop, and can be placed in toolbox.
  • Custom controls can be derived from different custom controls according to requirement.
  • Custom controls can be reused on multiple places easily.
  • Provide more flexibility in extending the control’s behavior.
  • Custom controls are loosely coupled control in respect to code an UI.
  • Custom controls can be used just by drag and drop into the form.
  • Custom controls have dynamic layout.

13. What is User Control?

  • A User control inherits from System.Windows.Controls.UserControls class.
  • User control defines UI as XMAL.
  • User control has fixed UI and can’t have different look in every project.
  • They are tightly coupled controls.
  • We can’t add them to the toolbox.
  • They are less flexible as compared to Custom controls
14. What are the Access Modifiers in C# ?
Different Access Modifier are - Public, Private, Protected, Internal, Protected Internal
  • Public – When a method or attribute is defined as Public, it can be accessed from any code in the project. For example, in the above Class “Employee” getName() and setName() are public.
  • Private - When a method or attribute is defined as Private, It can be accessed by any code within the containing class only. For example, in the above Class “Employee” attributes name and salarycan be accessed within the Class Employee Only. If an attribute or class is defined without access modifiers, it's default access modifier will be private.
  • Protected - When attribute and methods are defined as protected, it can be accessed by any method in the inherited classes and any method within the same class. The protected access modifier cannot be applied to classes and interfaces. Methods and fields in a interface can't be declared protected.
  • Internal – If an attribute or method is defined as Internal, access is restricted to classes within the current project assembly.
  • Protected Internal – If an attribute or method is defined as Protected Internal, access is restricted to classes within the current project assembly and types derived from the containing class. 

15. What are the features of C#?

  • C# is a powerful and simple programming language for writing applications.
  • Developers can easily build the web services through any language, on any platform across the internet.
  • C# is a hybrid of C++ and VB.
  • C# has many C++ features in the area expressions, operators and statements.
  • C# introduces improvement in boxing, unboxing, type safety, events, and versioning and garbage collections.
  • It reduces programming error in the code due to fewer lines of code.
  • C# has a key feature that can split up the implementation into logical pieces called region.
  • It support multiline comment feature.

16. What is an abstract class?

  • We can’t create the instance of an abstract class, because abstract classes are incomplete.
  • Abstract modifier doesn’t supported by interface, Values type and static types.
  • We can declare class as abstract by using abstract keyword in beggining of the class definition.
  • Abstract class provides similar definition of base class which can be shared by multiple derived classes.
  • Abstract class may define abstract methods by using the abstract keyword before the method definition.
  • Abstract methods have no implementation, only they can be implemented in the derived class.

    For Example:
    public abstract class Demo
    {
    public abstract void DoWork(int a);
    }
17. Different between method overriding and  method overloading?

In Overriding methods it will create two or more methods with same name and same parameter in different classes.

while Overloading it will create more then one method with same name but different parameter in same class.

18. Explain use of Abstract and Sealed Classes in C#?


The abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.

The sealed keyword enables you to prevent the inheritance of a class or certain class members that were previously marked virtual.

19. What is Managed code?

  • Manage Code are the codes which require common language runtime for its execution.
  • Managed code target the services of the common language runtime in .Net framework.
  • Managed code must provide the metadata necessary for the runtime to provide services like memory management, cross-language integration, code access security, and automatic lifetime control of objects.
  • Managed code provides services like cross-language integration, code access security, memory management and automatic lifetime control of objects by supplying necessary metadata for runtime.
  • Codes executed by Microsoft intermediate language are Managed code.

20. What is Un-Managed Code?

  • Code which is perfectly executed by operating system is known as un-managed code.
  • C, C++, VB 6.0 are examples of unmanaged code.
  • Un-managed code all the time dependent on computer architecture.
  • Un-managed code always compile to native code, so require compilation of code for different platform again and again.
  • Developers should take care of type safety, security, memory allocations.
21. What is Static Classes?

A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated.
In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself.

22. Explain Static Class Members.

A non-static class can contain static methods, fields, properties, or events.

The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created.

Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.

23. How does .NET remoting work?

  • .NET remoting is a process of sending messages through channels.
  • Standard channels in remoting are HTTP and TCP.
  • TCP is used for LANs only while HTTP can be used for LANs or WANs (internet).
  • Support can provided for many message serialization formats. Examples are SOAP (XML-based) and binary.
  • By default, the HTTP channel uses SOAP and the TCP channel uses binary. channela can use any serialization format.
  • There are two styles of remote access:
1) SingleCall. Every request from a client is serviced by a new object. The object is thrown away on completion of request.
2) Singleton. Single server object processed all request from clients.

24. Data Types in C#?

bool, byte , char, decimal , double, float, int, long, sbyte , short, uint, ulong, ushort.

25. What are attributes?

  • Attributes describe a type, method, or property in a way that can be queried using a technique call reflection.
  • Attributes specify which security privileges a class requires.
  • Attributes provide a description, title, and copyright notice to explain an assembly.
  • Attribute types derive from the System. Attribute base class and are declared using <> or [] notation.
  • Visual studio automatically creates some standard attributes for your assembly when you create a project including title, description, company, guide and version.
  • Attribute can also declare requirements or capabilities.

26. What are the File System Classes?

  • The file system classes are separated into two types of classes: information and utility.
  • Information classes derive from the FileSystemInfo base class.
  • Information Classes exposes all the system information about file system objects like files, directories and drives and named as FileInfo and DirectoryInfo classes.
  • DriveInfo class cannot derive from the FileSystemInfo class; it is an information class which represents a drive in the file system.
  • The utility classes have static methods to perform function on file system objects such as file system paths and Directories.
  • System.IO namespace contains collection of classes for files, drives and directories.
27. Types of comments in C#?


Single line comments
// for single line comments

Multiple line comments
/* for multi line comments */

XML tags comments

/// XML tags displayed in a code comment

28. Why Trim function is used in C#?

The Trim function is used to remove white spaces from the end and start of the instance.
Trim provide following methods as:

1) Trim(): This method of Trim is used to remove both off spaces from start and the end.
2) TrimStart(): This method of Trim is used to remove white spaces from the start of String.
3) TrimEnd(): This method of Trim is used to remove white spaces from the end of the string. 

No comments:

Post a Comment