C# Interview Questions Basic

  .Net interview questions, C#

What is c# language?

C# is the best language for writing Microsoft.net application. C# provides the rapid application development found in Visual Basic with the power of C++. Its syntax is similar to C++ syntax and OOPs like the following concepts.here we will discuss some important c# interview questions basic

  1. Abstraction.
  2. Inheritance
  3. Polymorphism.
  4. Encapsulation

What is enumerated datatype?

The enumerated data type is a subset of integral data type like e.g. byte, sbyte, short, ushort, int, uint, long, or ulong.it allow the programmer to use more meaningful words as values to a variable. the enumerated data type cannot be used with string type.

using System;					
public class Program
{
enum WeekDays
{
    Monday ,
    Tuesday,
    Wednesday=20,
    Thursday,
    Friday,
    Saturday,
    Sunday
}
	public static void Main()
	{
		Console.WriteLine((int)WeekDays.Wednesday);//output:20
		Console.WriteLine((int)WeekDays.Saturday);//output:23
	}
}

What are the different types of variables in C#?

Based on declaring the variable we categorized mainly three types of variables in C#

Local variable: local variables are declared in scope like inside a method or function this variable is not accessible outside with the scope only we will use

Global variable: global variable are accessible anywhere in the application like in side class or funcrion pr methods or with the name soace

Environment variable: this variabe are embeded in the special string with the equavalient of the varialbe,then it will return string type or array type

What is MS.NET visual studio?

MS.NET visual studio is an Application development environmental toolkit for building the different types of applications like web, windows, console, mobile…it includes dubbing tools, testing, deploying the application.

What’s the difference between BaseCassLibrary and FrameworkClasslibrary?

the base class library also we are called a class library. this class library is a collection pre implemented code and reusable types we will easily integrate into with CLR(common language run time).
but the framework class library contains hundreds of classes used to build different types of applications
and provides all the basic functionalities and services that application needs.

services to support different varieties of application Ex: ASP.Net, MVC, WCF.

What is namespace?

A namespace is a collection logically implemented class and this are unique types and each namespace has thousand of the related classes. for the namespace is like a Book where all the related classes are like chapters.

What is the Difference between NameSpace and Assembly?

Assembly: it is a physical grouping of logical units such as Namespace, logically group classes.
Namespace: it can multiple assemblies.

What is the Difference between NameSpace and Class?

Namespace: A namespace is a logical collection of classes and its types with unique names.
Class: Class is a blueprint.

What is the Application solution ?

An application solution is a group of Projects. One Solution can have many projects and the solution can of the same language or different languages. The Solution extension is .sln (ApplicationName.sln).

What is the mean of string[] args in function void Main()?

it contains any number of command-line arguments which we want to
pass to the Main() method.

What is WriteLine() and ReadLine() Method?

WriteLine(): WriteLine is a member method in Console Class. It prints the text on the console.

ReadLine(): Reads the next line of characters from the standard input stream.

What is the purpose of using statements in c#?

using the keyword used to include a namespace in the program. a program generally has multiple using statements

What is the difference between continue and break statements in C#?

break statement: using break statement you can jump out of a loop  Eg.break statement

class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i <= 7; i++)
            {
                if (i ==4)
                {
                    break;
                }
                Console.WriteLine("The numb:" + i);
            }
            Console.ReadLine();
        }
    }
Out put:
The numb:0
The numb:1
The numb:2
The numb:3

continue statement: using continue statement you can jump over one iteration’ and then resume your loop execution.

class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i <= 7; i++)
            {
                if (i ==4)
                {
                    continue;
                }
                Console.WriteLine("The numb:" + i);
            }
            Console.ReadLine();
        }
    }
    //OutPut
    The numb:0
    The numb:1
    The numb:2
    The numb:3
    The numb:5
    The numb:6
    The numb:7

What is the difference between a class and struct in C#?

Class and struct both are the user-defined data type but have some difference see given below differences

Struct:

  1. The struct is a value type and it inherits from System. Value Type.
  2. A struct is usually used for smaller amounts of data and it can’t be inherited from other types.
  3. A structure can’t be an abstract need to create an object by a new keyword.
  4. Do not have to create any default constructor.

Class

  1. The class is a reference type and it inherits from the System.Object Type.
  2. Classes are usually used for large amounts of data and Classes can be inherited from other classes.
  3. if A class can be abstract type We can’t use an object of a class with using the new keyword.

What is the difference between stack memory and heap memory?

Value type: variables are stored based on the scope if it is a local variable allocated in stack memory and if it is a global variable stored in heap memory. example:byte,int,long…Stack memory objects are self-managed.

Reference type: variables are stored always in heap memory.
example:string,object…etc. Heap memory managed by CLR.

What are the rules of C# language?

  1. Every class/struct/interface/enum must start with Curly bracket and end with Curly bracket.
  1. Every Method in c# must have parentheses(except anonymous methods).
  2. Every Method in c# must start with Curly bracket and end with Curly bracket.
  3. Every statement in c# ends with a semicolon.

What is the difference between the Convert and Parse method?

Convert: A convert method exists to convert every base type to every other base type.
Parse: Parsing is done whenever we are doing conversion form string to primitive data types.

What is the difference between Convert.ToInt32 and int.TryParse method?

Convert.ToInt32 possibility to throw format exception and int.TrParse returns true and false.

What is Boxing and Unboxing?

Boxing: The process of converting from value type to object type.
Unboxing: The process of converting from object type to value type.

Can we get using checked keyword for floating point arthimetics?

No, You cannot use the checked and unchecked keywords to control the floating-point
arithmetic(non-integer). The checked and unchecked keywords control only integer arithmetic. Floating-point arithmetic never throws OverflowException.

What is Implicit Casting and Explict Casting?

Implicit Casting: If every possible value of RHS expression is valid for a variable on LHS

Explicit Casting: If an RHS expression is assigned to LHS and if there is a possibility of data loss

What is Object?

the object is nothing but an instance of a class that has properties for identity is a state, methods for behavior and Events for depicting the Change of State

What is the Class?

A class is a template / skeleton / blueprint for creating an object.

An abstract class can implement a property?

Yes, Abstract class can have modifiers for methods, properties and An abstract class can implement a property.

public abstract class abstractModifier
{
      private int id;
      public int ID
      {
          get { return id; }
          set { id = value; }
      }
     internal abstract void Add();
} 

Resource Links:

C# technical Interview programs