Dot Net Interview Questions and Answers



Dot Net

Dot Net Interview Questions and Answers Online Training

Enroll Today

Top Dot Net Interview Questions and Answers - 2021 [UPDATED]

Are you looking for Dot Net Interview Questions and Answers? Than you are at the Right Place. Browse through Popular and Most Asked Interview Questions for Dot Net.  There is a Huge Demand for Dot Net Professionals in the Market. These Questions are suitable for both Freshers and Experienced Professionals and are based on Trending Topics and as per Current Industry Requirements.

Master These Topics and Increase your Chances in cracking Dot Net Interviews like a pro and Secure your Dream Job Today.

Dot Net Interview Questions and Answers

  • 50 Questions

Derived class inherits the member of base class is called inheritance. Its one object have all the properties and behaviors of its parent object. Using inheritance we can reuse the code. We can achive single level and multi level inheritance. public class Employee { public float salary = 400; } public class Programmer: Employee { public float bonus = 100; } class TestInheritance{ public static void Main(string[] args) { Programmer p1 = new Programmer(); Console.WriteLine("Salary: " + p1.salary); Console.WriteLine("Bonus: " + p1.bonus); } }

Two types of collections is there one is generic collection another one is non generic collection. Generic Collection: We can group one type of object in single collection is called generic collection. Here we dont need to convert particular type like string, int, etc. Non Generic Collection: We can group any type of object in single collection is called non generic collection. Here we need to convert particular type like string, int,etc., otherwise we will face issue in run time.

Array List Sorted List Stack Queue Hashtable Bit Array

It’s a method which have same name as class or struct name. It’s called automatically at the time of object creation.

Default Constructor Parameterized Constructor Copy Constructor Static Constructor Private Constructor

String Builder is a dynamic object. Its allow number of characters in string. Its does not create a new object in memory. StringBuilder sb = new StringBuilder(“Hi Team!!”); We can prefer StringBuilder. Beacuse it performs faster than string when appending multiple string values.

Function without name is called Anonymous functions. Two types of anonymous functions. Lambda Expressions Anonymous Methods

It is a process to get metadata of a type at runtime. Few classes for reflection are below, Type Assembly Assembly Name

Its declared as abstract. It can have abstract and non-abstract methods. It cannot be instantiated. Its implementation must be provided by derived classes.

Its a restrictions of class and methods. Sealed class cannot be derived and Sealed method cannot be overridden.

Derived class define same method as defined in base class. Its need to use virtual keyword with base class method and override keyword with derived class method. public class Sample{ public virtual void message(){ Console.WriteLine("Hi Welcome"); } } public class SampleTwo: Sample { public override void message() { Console.WriteLine("Hello"); } } public class TestOverriding { public static void Main() { SampleTwo d = new SampleTwo(); d.message(); } }

Its wrapping data into a single unit. class Employee { public string ID { get; set; } public string Name { get; set; } } class example { static void Main(string[] args) { Employee employee = new Employee(); employee .ID = "1"; employee .Name = "Anbu"; Console.WriteLine("ID = "+employee .ID ); Console.WriteLine("Name = "+employee .Name ); } }

Authentication Authorization Result Action Exception

We can use multiple model in Single view using below things, View Data View Bag Tuple Dynamic Model View Model

It has rich GUI controls, secured, integrated with many Microsoft applications, scalability and stability, support many programming languages, rich SOLID principals, portable, it supports various architectures and design patterns, easy to maintain and deploy.

Easiest way to code with a powerful IDE (Visual studio), with better flexibility, rich development community, no compromise with the security, top deploying solution with Microsoft azure cloud integration.

Page processing can be transferred from one page to other page with the help of server.transfer without making a post back to the browser. Redirection of the page from another page can be achieved with the help of response.redirect which perform a post-back to the client browser.

By using the SynchronizedCollection has a built-in synchronization object which can be used to make collection thread-safe, and this can be used for specific requirement.

Immutable collection take a different approach in making collections thread-safe. As concurrent collections use synchronization locks instead, immutable collections can’t be changed after they are created. Automatically it makes them safe to use in multi-threaded scenarios since there’s no way for another thread to modify them and make the state inconsistent. This design decision definitely affects the API of immutable collection classes. They don’t even have public constructors.

Honest method is a function whose output depends on its input parameters and that does not have any side effects. Which means that a pure method cannot mutate an argument, cannot read or mutate global state, cannot read the system timer, cannot read or write file contents, cannot read from or write to the console, etc.

C# discourages or prevents data type errors, the data type error is un-desirable program behavior caused by variation between differing datatype for the program variables, constants and functions this is the reason behind C# a type safe language.

The System.Object type is CLS compliant and it is base type of all object types in the .NET Framework type system. Inheritance in the .NET Framework is either implicit (for example, the String class implicitly inherits from the Object class) or explicit (for example, the CultureNotFoundException class explicitly inherits from the ArgumentException class, that is explicitly inherited from the Exception class. For a derived type to be a CLS compliant, its base type must also be CLS compliant.

The following intrinsic types are not CLS-Compliant. SByte – 8-bit signed integer data type, TypedReference – Pointer to an object and its runtime type, Uint16 – 16-bit unsigned integer, Uint32 – 32-bit unsigned integer, Uint64 – 64-bit unsigned integer, UintPtr – Unsigned pointer or handle.le.

Views that don’t declare a model type using @model but that have a model instance passed to them (for example, return View(Address)) can reference the instance’s properties dynamically. The feature offers flexibility, but it doesn’t offer compilation protection or IntelliSense. If the property doesn’t exist, then webpage generation fails at run-time.

Generic types to maximize code re-usability, type safety, and performance. The main common use of generics is to create collection classes. The .NET Framework class library contains many new generic collection classes in the System.Collections.Generic namespace. These can be used whenever possible instead of classes such as ArrayList in the System.Collections namespace. We can create our own generic interfaces, classes, methods, events and delegates. Generic may be constrained to enable access to methods on data types. The information on the types that are used in a generics data type may be obtained at run-time by using reflection.

In .NET Framework delegates provide a late binding mechanism. it means which we create an algorithm where the caller also supplies at least one method that implements part of the algorithm. Consider sorting a list of stars in an astronomy program. we may choose to sort those stars by their distance from the earth, or the magnitude of the star, or their perceived brightness.

The following steps are involved in the life cycle of the winforms in .net Load: When the form is loaded in into application. Activate: When the form gets focused when it loads for the first time. Deactivate: When the form is not focused or minimized or sent to background. Closing: Before closing the application, this functionality is invoked. Closed: When application is closed. Disposed of: Garbage collection performs once the application is closed.

By using the Form.ParentForm property of the dialog box we can access the public members of the form. And we can explicitly convert the reference returned by the ParentForm property to appropriate type.Below code will help us to demonstrate the ParentForm property to access a property from the form. public void GetParent() { string x = ((Form1)this.ParentForm).Text; }

In The singleton design pattern, only one Instance of a class will be created and will be used to provide access point globally Below code will demonstrate the Singleton Design Pattern in C# public sealed class Singleton { private static readonly Singleton obj = new Singleton(); }

OutOfMemoryException, ArithmeticException, NullReferenceException, OverflowException, InvalidOperationException, ArgumentException, DivideByZeroException, IndexOutOfRangeException, InvalidCastException, IOEndOfStreamException, ArgumentOutOfRangeException, ArgumentNullException, StackOverflowException and so on

Defining multiple constructors with the same name within the same class but with different arguments in different sequence can be said as constructor overloading.

When a class constructor is invoking another class, constructor is called as constructor chaining. Base() can be used as constructor chaining.

When we run the application the CLR will invoke Main(). If the Main() is a instance method it requires object. To succeed this, Main() method is defined as static method.

Dot Net will support multiple languages. When developing an application using dot net languages we can use another dot net language component. Ex – When we develop C# dot Net application we can use component. As well as when we develop VB.Net application we can use C# dot Net component. Because of this reason dot net is independent technology.

IsPostBack is the property of the web Page class which is used to determine whether the page is posted back from the client. Whenever we don’t want to execute the code within the load event, then the page load event fires then we will use (!IsPostBack)

Autopostback is the property of the controls. If you need a control to post back automatically when an event is raised, we need to set the AutoPostBackproperty of the control as True.

Yes. We can convert Client-side control as server-side control by adding an attribute runat= server But, we cannot convert server-side control to client-side control

Whenever we need to define some separate settings for couple of web pages, we can create a new folder and we can add those couple of web pages to that folder and we should add a new Web.config file to that new folder and we can define separate settings within that Web.config

Machine.Config file, this file specifies the settings that are global to a particular system, Machine.config file is used to configure the application according to a system. That is, configuration done in machine.config file is affected on any application that runs on a system. Usually, this file is not altered. We can have only one machine.config file in a system.

Advantages of Inproc Session are as follows Accessing the inproc session data will always be faster. It is always good for small web applications Disadvantages of Inproc session are as follows It we restart the web server or if any crashes to the web server there is a chance of losing the session data. If the session data is increased there is a burden on the web server, it will affect the performance of web server and web application. It is not suitable for large web application models like web-garden and web-farm.

There are overall 8 stages for any webpage in Asp.Net which will undergo within server at page life cycle. Page Request Start Page Initialization Load Validation PostBack Event Handling Rendering Unload

Enum is a value type. Enum is a collection of constants which means it is a collection of string constants which are representing collection of integer constants. Int is the default data type of enum.

We can pass 2 different type values to generic collection. Please find the below code which demonstrates Class MyClass { Internal static void print (Ta, Kb) { } } Class program { public static void Main () { MyClass.print(05,"Besant"); Console.ReadLine (); } }

By using Thread.sleep(), we can send a thread to sleep according to the given time. Sleep () method can be blocked the current thread for the specified number of milliseconds. In other words We can include specific time via thread.sleep() method as follows. Thread.Sleep (TimeSpan.FromHours (1)); // sleep for 1 hour Thread.Sleep (1000); // sleep for 1000

Boolean literals: False or True are literals of the boolean type which map to the 0 and 1 state, respectively. Integer literals: Interger is used to have values of types Int, ulnt, long, and ulong. Real literals: Real is used to have values of types float, double, and decimal. Character literals: character represents a single character and usually consists of a character in single quotes, such as ‘a’. String literals: Dotnet supports 2 types of string literals, regular string literal and verbatim string literals. A regular string consists of zero or more characters within the double quotes, such as “543234”. A verbatim string literal is of an @ character followed by a double–quote character, such as @”This is litrals”. The Null literal: Represents the null–type.

No, In C# a method cannot be declared as sealed. But when we override a method in a derived class, we can declare the overridden method as sealed. By declaring it as sealed, we can avoid further overriding of the sealed method.

Each web control has an ability to add the attributes on client side that will execute on client side and run a client-side script like a JavaScript function. Ex – btnSubmit.Attributes.Add (“onMouseOver”,”someClientCode();”) TextBox.Attributes.Add(“onFocus”,”ClearText();”)

Using is a convention or a short-cut method which allows us to access the classes in a namespace by referencing it on top of the class. whenever we need to use the classes or methods from the namespace, we can avoid typing the entire namespace hierarchy.

If the child class don’t want to use methods from the base class, child class can implement its own version of the same method with same signature. For example, in the classes below, Pipedrive () is implemented in the child class with same signature. This can be called as Method Hiding. class Car { public void TypeOfDrive() { Console.WriteLine("Right Hand Drive"); } } class Ford : Car { public void TypeOfDrive() { Console.WriteLine("Right Hand "); } }

Yes, Custom Exception class is nothing but a user defined class which is derived from System Exception class. Below are the steps, Custom class can be derived from System Exception class. By Creating a constructor of custom class with error message parameter and we can pass it to the base class (System Exception class). Then throw and catch custom exception message in try-catch block in code wherever it is required.