UNIT – I

1. What is C#?

  1. C# (pronounced as 'c’ sharp') is a new computer-programming language developed by Microsoft Corporation, USA.
  2. C# is a fully object-oriented language like Java and is the first Component- oriented language. It has been designed to support the key features of .NET Framework, the new development platform of Microsoft for building component-based software solutions.

2. Why are you using C#?

1. The high complexity of the language

2. Their long cycle-time

3. They are not truly object-oriented

4. They are not suitable for working with new web technologies

5. They have poor type-safety

6. They are prone to costly programming errors

7. They do not support versioning

8. They are prone to memory leakages

9. Their low productivity

10. Their poor interoperability with the existing systems

11. VB is not truly an object-oriented programming language, it becomes

12. Increasingly difficult to use when systems become large.

13. Java, a language derived from C / C++ family, however, is truly object-oriented and has been widely used for web applications for the past five years. Unfortunately, Java has not retained some powerful C++ features such as operator overloading.

3. What are the characteristic for the C#?

1. Simple2. Consistent3. Modern4. Object – Oriented

5. Type – Safe6. Versionable 7. Compatible8. Interoperable

9. Flexible

4. List out application for the C#.

  • Console applications
  • Windows applications
  • Developing Windows controls
  • Developing ASP.NET projects
  • Creating Web controls
  • Providing Web services
  • Developing .NET component library

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

  • C# does not support #include statement. (Note that using is not the sameas#include).
  • C# checks for uninitialized variables and gives error messages at compile time. In C++, an uninitialized variable goes undetected thus resulting in unpredictable output.
  • C# supports four iteration statements rather than three in C++. The fourth one is the foreach statement.
  • When overriding a virtual method, we must use the override keyword.
  • Abstract methods in C# are similar to virtual functions in C++, but C# abstract methods cannot have implementations.

6. What are the C++ features dropped in C#?

The following C++ features are missing from C#:

1. Macros2. Multiple inheritances3. Templates4. Pointers

5. Global variables6. Typedef statement7. Default arguments8. Constant member functions or parameters 9. Forward declaration of classes

7. What are features Enhancements to C++ in C#?

1. Automatic garbage collection2. Versioning support3. Strict type-safety 4. Delegates and events 5. Boxing and unboxing 6. Web services

8. How does C# differs from Java?

1. C# supports the struct type and Java does not.

2. Java does not provide operator overloading,

3. C# provides built – in delegates and events. Java uses interfaces and inner classes to achieve a similar result.

4. C# provides a fourth type of iteration statement, foreach for quick and easy iterations over collections and array type data.

5. C# checks overflows using checked statements.

6. C# uses is operator instead of instanceof operator in Java.

7. C# allows a variable number of parameters using the params keyword.

9. What are the Microsoft .NET products and services consist of the following:

. Windows .NET. MSN .NET. Office .NET. Visual Studio .NET

. Personal subscription services. bCentral for .NET

10. What is Common Language Runtime (CLR)?

The Common Language Runtime, popularly known as CLR is the heart and soul of the .NET framework. As the name suggests, CLR is a runtime environment in which programs written in C# and other .NET languages are executed. It also supports cross-language interoperability.

The CLR provides a number of services that include:

  • Loading and execution of programs
  • Memory isolation for applications
  • Verification of type safety
  • Compilation of IL into native executable code
  • Providing metadata

11. What is Common Type Systems (CTS)?

  • The .NET framework provides multiple language support using the feature known as Common Type System that is built into the CLR.
  • The CTS supports a variety of types and operations found in most programming languages and therefore calling one language from another does not require type conversions.
  • Although C# is specially designed for the .NET platform, we can build .NET programs in a number of other languages including c++ and Visual Basic.

12. What is Common Language Specification (CLS)?

  • The Common Language Specification defines a set of rules that enables interoperability on the .NET platform.
  • These rules serve as a guide to third-party compiler designers and library builders.
  • The CLS is a subset of CTS and therefore the languages supporting the CLS can use each others' class libraries as if they are their own.
  • Application Program Interfaces (APIs) that are designed following the rules of CLS can easily be used by all the .NET languages.

13. What is Microsoft Intermediate Language (MSIL)?

  • MSIL, or simply IL, is an instruction set into which all the .NET programs are compiled.
  • It is akin to assembly language and contains instructions for loading, storing, initializing and calling methods.
  • When we compile a C# program or any program written in a CLS-compliant language, the source code is compiled into MSIL.

14.Briefly explain the JIT (Just – in – Time) compiler.

  • Before MSIL can be executed, it must be converted by a .NET Framework Just –In-Time (JIT) compiler to native code, which is CPU – specific code that runs on the same computer architecture that the JIT compiler is running on.
  • Because the runtime supplies a JIT compiler for each CPU architecture that the runtime operates on, developers can write a set of MSIL that can be JIT – compiled and executed on computers with different architectures.
  • The idea behind JIT compilation recognizes the fact that some code may never get called during execution.
  • As part of compiling MSIL to native code, the code must pass a verification process.
  • Verification examines MSIL and metadata to see whether the code can be determined to be type-safe, which means that it is known to access only the memory locations it is authorized to access.

15. What is an Assembly?

An assembly is the functional unit of sharing and reuse in the Common Language Runtime. It provides the Common Language Runtime with the information it needs to be aware of type implementations.

16. What is Managed Code and Unmanaged Code?

Managed Code

  • The Code is Understandable by CLR.
  • It is executed under the instructions of CLR.
  • The code which is done by .net compatible language will be compiled two times. In the first compilation, the compiler will generate MSIL code. Which is known as Managed Code.

UnManaged Code

  • The CLR cannot able to understand the code.
  • The CLR cannot instruct the code.
  • The second time compilation is unmanaged code. It is understood only by the machine not by the user.

17. What are the framework Base classes?

1. String handling2. Managing arrays, lists, maps, etc3. Accessing files and file systems

4. Accessing the registry5. Security6. Windowing 7.windows messages

8. Database management9. Evaluation of mathematical functions10. Drawing

11.Managing errors and exceptions12. Connecting to the Internet13.Input/Output Operations

18. What are the User and Program interface in .Net?

The .NET framework provides the following tools for managing user- and application interfaces:

  • Windows forms
  • Web forms
  • Console Applications
  • Web services

19. What are benefits for the .Net?

  • Simple and faster systems development
  • Rich object model
  • Enhanced built-in functionality
  • Many different ways to communicate with the outside world
  • Integration of different languages into one platform
  • Easy deployment and execution
  • Wide range of scalability

20. What is Command Line Argument?

There may be occasions when we may like our program to behave in a particular way depending on the input provided at the time of execution. This is achieved in C# by using what are known as comman line arguments. Command line arguments are parameters supplied to the Main method at the time ( invoking it-for execution.

using system;

class SampleSix

{

public static void Main (string [] args)

{

Console.Write ("welcome to");

Console.Write (" "+args [0]);

Console.WriteLine (" "+args[1]);

}

21. C# has to support multiple main methods. Justify your answer.

We have stated earlier that one of the classes must have the Main method as a member. This is what' I normally expected. However, C# includes a feature that enables us to define more than one class wipI:i the Main method. Since Main is the entry point for program execution, there are now more than 1 entry points. In fact, there should be only one. This problem can be resolved by specifying which is to be used to the compiler at the time of compilation as shown below:

csc filename.cs/main:classname

Filename is the name of the file where the code is stored and classname is the name of the containing the Main which we would like to be the entry point.

The following simple program that has two classes containing Main methods. It in a file called multimain.cs and compile it using the switch

main:ClassA or main:ClassB as required

using System;

class ClassA

{

public static void Main( )

{

Console.WriteLine("Class A");

}

}

class ClassB

{

public static void Main( )

{

Console.WriteLine("Class B");

}}

22. What are the difference between Value type and Reference type?

  • Where they are stored in the memory
  • How they behave in the context of assignment statements

Value types

Value types (which are of fixed length) are stored on the stack, and when a value of a variable in assigned to another variable, the value is actually copied. This means that two identical copies of the value are available in memory.

Reference types

Reference types (which are of variable length) are stored on the heap, and when an assignment between two reference variable occurs, only the reference is copied; the actual value remains in the same memory location. This means that there are two references to a single value.

23. What is boxing and Unboxing? Give an example.

Since value type such as int and long are not objects we cannot use them to call methods. C# enables us to achieve this through a technique known as boxing. Boxing means the conversion of a value type on the stack to a object type on the heap. Conversely, the conversion from an object type back to a value type is known as unboxing.

Boxing

Any type, value or reference can be assigned to an object without an explicit conversion. When the compiler finds a value type where it needs a reference type, it creates an object ‘box’ into which it places the value of the value type.

int m = 100;

object om = m;

Ex:

int m = 10;

object om = m;

m = 20;

Console.WirteLine (m);// m = 20

Console.WriteLine(om);//om = 10

When a code changes the value of m, the value of om is not affected.

UnBoxing

Unboxing is the process of converting the object type back to the value type.

int m = 10;

object om = m;

int n = (int) om;

When performing unboxing, C# checks that the value type we request is actually stored in the object under conversion. Onlyif it is , the value is unboxed.

When unboxing a value, we have to ensure that the value type is large enough to hold the value of the object. Otherwise, the operation may result in a runtime error. For example, the code

int m = 500;

object om = m;

byte n = (byte) om;

will produce a runtime error.

24. List out the operators in C#.

  • Arithmetic operators
  • Relational operators
  • Logical operators
  • Assignment operators
  • Increment and Decrement operators
  • Conditional operators
  • Bitwise operators
  • Special operators

25. What are special operators in C#?

is Operatoras Operatortypeof Operatorsizeof Operatornew Operator . (dot) Operator checked Operator unchecked Operator

26. Write the Syntax for the foreach statement in C#?

The foreach statement is similar to the for statement but implemented differently. It enables us to iterate the elements in arrays and collection classes such as List and Hash Table.

The general form of the foreach statement is:

foreach (type variable in expression)

{

Body of the Loop

}

27. What is the advantages for the foreach statement over the for loop?

The advantage of foreach over the for statement is that it automatically detects the boundaries of the collection being iterated over.

28. How to achieve the fall through statement in C#?

To achieve the fall through statement in C# is to implement to the goto statement in the switch case statement. For Example:

Switch(ch)

{

case: 1

Console.WriteLine(“This is A”);

goto 2;

case: 2

Console.WriteLine(“This is B”);

goto 3;

case: 3

Console.WriteLine(“This is C”);

goto default;

default:

Console.WriteLine(“End of the Switch Case”);

}

29. List out the method modifiers.

30. What are the advantages for the Structures?

  • They are created much more quickly than heap – allocated type.
  • They are instantly and automatically deallocated once they go out of scope.
  • It is easy to copy value type variables on the stack.

31. Define a struct:

A struct in C# provides a unique way of packing together data of different types. It is a convenient tool for handling a group of logically related data items. It creates template that may be used to define the data properties. Once the structure type has been defined, we can create variable of that type using declarations that are similar to the built – in type declarations.

Syntax:Example:

struct struct-namestruct Student

{{

data member1;public string name;

data member2;public double totalmarks;

}}

32. List out the differences between Classes and Structures

Category / Classes / Structs
Data Type / Reference type and therefore stored on the heap / Value type and therefore stored on the stack.
Inheritance / Support Inheritance / Do not support inheritance
Default Values / Default value of a class type is null / Default value is the value produced by ‘zeroing out’ the fields of the struct.
Field initialization / Permit initialization of instance fields / Do not permit initialization of instance fields.
Constructors / Permit declaration of paramerterless constructors / Do not permit declaration of parameterless constructor
Destructor / Supported / Not Supported
Assignment / Assignment copies the reference / Assignment copies the values.

33. Define Enumeration.

An Enumeration is a user – defined integer type which provides a way for attaching names to numbers, thereby increasing the comprehensibility of the code. The enum keyword automatically enumerates a list of words by assigning them values 0,1,2 and so on. This facility provides an alternative means of creating ‘constant’ variable names.

Syntax:

enum Shape

{

Circle,

Square,

Triangle

}

OR

enum Shape {Circle, Square, Triangle}

34. What is Verbatim Strings?

Verbatim strings are those that start with the @ symbol. This symbol tells the compiler that the string should be used verbatim even if it includes escape characters.

string s1 = @ “\EBG\CSharp\string.cs”;

(or)

string s1 = \\EBG\\CSharp\\string.cs;

35. What is the Usage of Checked Operator in C#?

Checked Operator is used to validate the arithmetic expression to know whether any overflow occur as a result of the given expression. If Overflow occurs its throws an exception indicating the overflow.

36. Differentiate the String and String Builder type in C#?

String / String Builder
Immutable String type,that we cannot modify the characters that contained in them. / Mutable String type, these types accept the changes.
All operations results in a modified version of a new string / Operations carried out on the original string only.

37. What are the advantages that properties can have over the variables?

Properties combine the fields with the methods that access it. It provides more control over the fields and makes accessible the private variables outside the class using properties.

38. Can we create a copy of an existing array and make the changes without affecting the original array?

Yes, we can create the exact copy of the original array and modify the without changing the original array using the Clone method of array type.

39. How does DOT.Net achieve Interoperability?

Dot.net achieve interoperability with the help of Common Type System (CTS), every language that run in the .net platform has to obey the minimum set of rules. Each language can interact with each other using the CTS and CLS.

40. What are the different ways that a parameter passes to a method?

  • Pass By value
  • Pass by Reference
  • Out parameter and
  • Params array

UNIT – II

1. What are the access modifiers in C#?

2. What are the restrictions for the Static methods?

1. They can only call other static methods.

2. They can only access static data.

3. They cannot refer to this or base in any way.

  1. What is the Condition for the Static Constructor?
  • It is usually used to assign initial values to static data members
  • It cannot have any parameters.
  • There is no access modifier on static constructors.
  • A Class can have only one static constructor.
  1. When the Instances and Static variable assign the initial values?

a. Static variables are assigned when the class is loaded.

b. Instance variables are assigned when an instance is created.

4.A. When the Instance and Static variable assign the default values?

a. Static variables are initialized to their default values when the class is loaded.

b. Instance variables are initialized to their default values when an instance is created.

  1. What is the purpose of the ‘this’ keyword?

1. C# supports the keyword this which is a reference to the object that called the method.

2. The this reference is available within all the member methods and always refers to the current instance.

3. It is normally used to distinguish between local and instance variables that have the same name.

  1. What are the drawback for the Accessor Methods?
  • We have to code the accessor methods manually.
  • User have to remember that they have to use accessor methods to work with data members.

7. What are the powerful features for the properties?