Explore 1.5M+ audiobooks & ebooks free for days

Only $12.99 CAD/month after trial. Cancel anytime.

C# Interview Questions You'll Most Likely Be Asked
C# Interview Questions You'll Most Likely Be Asked
C# Interview Questions You'll Most Likely Be Asked
Ebook210 pages1 hourJob Interview Questions Series

C# Interview Questions You'll Most Likely Be Asked

Rating: 0 out of 5 stars

()

Read preview

About this ebook

  • 284 C# Interview Questions
  • 78 HR Interview Questions 
  • Real life scenario based questions
  • Strategies to respond to interview questions
  • 2 Aptitude Tests

C# Interview

LanguageEnglish
PublisherVibrant Publishers
Release dateDec 14, 2016
ISBN9781946383099
C# Interview Questions You'll Most Likely Be Asked

Other titles in C# Interview Questions You'll Most Likely Be Asked Series (30)

View More

Read more from Vibrant Publishers

Related to C# Interview Questions You'll Most Likely Be Asked

Titles in the series (33)

View More

Related ebooks

Programming For You

View More

Reviews for C# Interview Questions You'll Most Likely Be Asked

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    C# Interview Questions You'll Most Likely Be Asked - Vibrant Publishers

    C Sharp

    Interview Questions

    You'll Most Likely Be Asked

    Job Interview Questions Series

    www.vibrantpublishers.com

    *****

    C Sharp Interview Questions You'll Most Likely Be Asked

    Copyright 2021, By Vibrant Publishers, USA. All rights reserved. No part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior permission of the publisher.

    This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. The author has made every effort in the preparation of this book to ensure the accuracy of the information. However, information in this book is sold without warranty either expressed or implied. The Author or the Publisher will not be liable for any damages caused or alleged to be caused either directly or indirectly by this book.

    Vibrant Publishers books are available at special quantity discount for sales promotions, or for use in corporate training programs. For more information please write to [email protected]

    Please email feedback / corrections (technical, grammatical or spelling) to [email protected]

    To access the complete catalogue of Vibrant Publishers, visit www.vibrantpublishers.com

    *****

    Table of Contents

    1. Introduction

    2. Assemblies and Security

    3. Data Access

    4. Keywords

    5. Windows Applications

    6. Web Application

    7. Remoting and Webservices

    HR Questions

    Index

    *****

    C Sharp

    Interview Questions

    Review these typical interview questions and think about how you would answer them. Read the answers listed; you will find best possible answers along with strategies and suggestions.

    *****

    Introduction

    1: How can you get input from command line?

    Answer:

    Console.Readline() is the command which prompts the user to enter the value for a variable or an argument. A sample example is as follows:

    // Namespace Declaration

    using System;

    // Program start class

    class UserInput

    {

    // Main indicates the beginning of program execution.

    public static void Main()

    {

    // To Write in console OR To get input from Console

    Console.Write(Where are you from?: );

    Console.Write(I am from, {0}! , Console.ReadLine());

    }

    }

    On execution of above program prints Where are you from?: and waits for the user input. User should type the value and press enter key to continue.

    2: Why do we need Command line input?

    Answer:

    Many windows utilities have some type of command line interface. When we type notepad filename.txt in command line, notepad will open the contents of your filename provided.

    Command line inputs facilitate to write scripts that can invoke the program to pass values through arguments.

    3: How does shallow copy differ from deep copy?

    Answer:

    Deep copy:

    a) It is creation of new instance of an object

    b) It copies all fields and creates copies of memory allocation pointed to by the fields

    Shallow copy:

    a) It is a bit wise copy of an object

    b) It holds the references to the same object and in other terms copies the address where the values are stored

    4: What is a delegate in C#?

    Answer:

    Delegates are used to define methods callback. They are similar to the function pointer of C++. Methods can be passed as arguments using delegates.

    Using delegates multiple methods can be invoked on a single event.

    For example: int i = int.Parse(99); -

    5: What is a sealed class?

    Answer:

    Class name prefixed with sealed keywords prevents the ability to inherit the properties and methods of the class. Methods of a sealed class can be called by creating objects for the class. Sealed keyword is similar to final keyword in Java.

    Example for sealed class:

    public sealed class mySealedclass

    {

    public string name;

    public double quotation;

    }

    Creating object for a sealed class:

    mySealedclass msc=new mySealedclass ();

    6: How can you achieve multiple inheritance in C#?

    Answer:

    Multiple inheritance is not supported in C#. This can be achieved using Interface. Interfaces are classes where methods and properties can be defined.

    Methods implementations will not be available within the class. Also, an interface cannot be instantiated directly. Multiple interfaces are supported in C# as a replacement for multiple inheritance.

    7: What is a reflection?

    Answer:

    Reflection is the ability to find information about objects. Compilers for languages such as JScript use reflection to construct symbol tables.

    The namespace System.Reflection defines the Assembly, ParameterInfo, Enum, Module, MemberInfo, MethodInfo, Type, FieldInfo, ConstructorInfo, PropertyInfo, and EventInfo types to analyze the metadata of an assembly.

    8: What is a metadata?

    Answer:

    Metadata contains a number of different tables; for example, a type definition table, a filed definition table, a method definition table, and so forth.

    By parsing these tables, we can get an assembly's types and attributes.

    9: Are nullable datatypes supported in C#? If No explain the reason for this, if Yes describe which property can be used to check of null value and which to get the value. (1.b)

    Answer:

    C# supports nullable datatypes. Nullable types represent value type variables that can be assigned the value of null. A typical scenario for null datatypes is on databases that it contains elements that may be not assigned a value. You can assign a value to a nullable type the same way you assign a value to other value types, for example int? x = 10. HasValue and Value properties are used to test for null and retrieve the value respectively.

    10: What are error types available in C#?

    Answer:

    Following are the error types in C#:

    a) Run-Time Error

    b) Parser Error

    c) Configuration Error

    d) Compilation Error

    11: What is a Constructor?

    Answer:

    The following are the key points about a constructor:

    a) The method name is the same name as that of the class

    b) Never returns a value

    c) Can be overridden to provide custom initialization feature

    d) Get executed as first method when an object is created

    e) Used to initialize class and structure the data before use

    12: What is the use of keyword static?

    Answer:

    A function/variable named with keyword static can be called using the class name and object creation is not required. Keyword ‘this’ cannot be used within a function which is defined as a static function. Static constructors can be created in C#.

    class MyClass

    {

    static MyClass()

    {

    // static construction code

    }

    In the above example, we have a static method MyClass() which gets executed whenever the class is loaded.

    13: What is Dispose?

    Answer:

    Dispose method is used to release memory for an object. Dispose method is part of IDisposable interface.

    Dispose method has no arguments and it returns void. If a class wants to declare publicly that it implements the Dispose() method, it must implement IDisposable

    .dispose will release the memory.

    14: What is enumeration?

    Answer:

    An Enumeration is a user-defined integer type. Enumerations make the code easier to maintain by ensuring that variables assigned are only legitimate. It also allows you to refer to integer values by descriptive names.

    Example of Enumeration is mentioned below:

    Public enum TimeOfDay

    {

    Morning = 0, Afternoon=1, Evening=2

    }

    Enumeration can be accessed as

    TimeOfDay.Morning

    15: What do you know about Enumeration Types? Why use an enumeration instead of a numeric type?

    Answer:

    An enumeration type can be used to define a set of named constants. One typical scenario is to define an enumeration type Days containing seven values each representing a day of a week. By default the underlying type of each element in the enum is int, however using a colon you can specify other numeric types such as byte. Enum keyword is used for the declaration of enumeration types. The advantages of using an enum instead of a numeric type is that you clearly set which values are valid for the variable and that it improves code readability.

    16: Describe the differences between String and StringBuilder. When is it recommended to use a StringBuilder instead of a String object?

    Answer:

    String is an immutable type. Immutable means that an operation to String instance isn’t executed on the same instance, but a new String is created instead. On the other side StringBuilder is a mutable type, meaning that all operations of modifying an instance such as remove, add, insert and other operations are executed on the same instance. StringBuilder should be used at scenarios where performance is important, for example when an application needs to make significant number of changes to a string.

    17: What is the use of keyword Monitor?

    Answer:

    Using Monitor, a particular section of application code can be blocked by other threads while the code is being executed. Object locks provide the ability to restrict access to a block of code, commonly called a critical section.

    Monitor is associated with an object on demand. An instance of a monitor class cannot be created. It can be called directly from any context. Monitor class controls access to objects by granting a lock for an object to a single thread.

    18: Compare values types with reference types.

    Answer:

    a) In value type, values are stored in stack and for reference type it is stored on heap.

    b) When values types are not initialized default values will be 0, false. In case of reference type null will be set if not initialized.

    c) Variables of value type contain values and reference types contain references.

    19: What is an array and what are types are arrays available?

    Answer:

    Array is a collection of related instances. It can be reference or a value

    Enjoying the preview?
    Page 1 of 1