Adv C#
Programming

1. Introduction to .NET and C# 2. Points to keep in mind for pyramid 3. C# Pyramid Program Example for type 1 4. C# Pyramid Program Example for type 2 5. C# Pyramid Programs on Type 3 6. C# Pyramid Programs of type 4 7. C# Pyramid Programs of type 5 8. Classes and Objects 9. Recursive functions 10. Constructors in C# 11. Destructor 12. Method Overloading 13. Constructor Overloading 14. Inheritance in C# 15. Interface in C# 16. Method Overriding 17. readonly and sealed keyword in C# 18. Exception Handling 19. Delegates 20. Multicast Delegates 21. Events 22. Structure 23. Threads 24. Working with Threads 25. Thread Life Cycle 26. Introducing Multithreading 27. Advantage and limitation of multithreading 28. Thread priority 29. Properties 30. Collections 31. ArrayList Class 32. Hastable Class 33. SortedList 34. Stack 35. Queue Class 36. Generics 37. Unsafe code 38. C# Networking 39. Prgs for Science and Engineer 40. Prg to use alias 41. Prg to count minors and majors using array 42. Prg for sum up of two array in third array 43. Prg to show boxing and unboxing 44. Prg for type casting from byte to int 45. Prg to find area of circle 46. Prg to find cube root of entered number 47. Prg for digit manipulation 48. Prg for printing a reverse triangle 49. Prg to show case and goto fall through 50. Prg to show use of foreach loop 51. Prg for adding 2 numbers 52. Prg to show jagged array 53. Prg to show different methods of Array 54. Prg to print number Pyramid 55. Prg to show entered string is palindrome or not 56. Prg to show entered number is prime or not 57. Prg to show different methods of StringBuilder 58. Prg to show different methods of String 59. Prg for appending a string using StringBuilder 60. Prg to show appending a string with numeric type data using StringBuilder 61. Prg to show use of ArrayList 62. Prg to pass an array as a parameter to a function for finding out a prime number 63. Prg to show the constant member 64. Prg for showing destructor 65. Prg for sum up and reversing the entered number 66. Prg for enum type conversation 67. Prg to show sum of first fifty even and odd number 68. Prg to find the factorial of entered number 69. Prg for iterating each element of array using foreach loop 70. Prg to show array position and value 71. Prg to show how to insert and remove string using StringBuilder 72. Prg to show how to join the string 73. Prg to show the value of sin 90 74. Prg to enter two number and find max 75. Prg to show padding 76. Prg to show entered number is prime or not 77. Prg to show private constructor 78. Prg to show how to use getter and setter property 79. Prg using out parameter 80. Prg to count the number of spaces and words in a String 81. Prg to show how to use Split method 82. Prg to create binary triangle 83. Prg to create dule star triangle 84. Prg to create triangle 85. Prg to show use of EndsWith and StartsWith method of string 86. Prg for static constructor 87. Prg to show how to use insert method 88. Prg to sort a string 89. Prg to store student name and roll no using structure 90. Prg to show how to use delegate 91. Prg to calculate depreciation 92. Prg for calculating Economic order cost and time between order 93. Prg to find radius of circle 94. Prg to sum up odd numbers from 0 to 20 95. Prg to calculate simple interest 96. Prg to categorise student on base of there marks range where marks are stored in array 97. Prg to create triangle on console screen 98. Prg to print sin theta, cos theta and tan theta from 0.1 to 1.0 angle in radians 99. Prg to demonstrate variables 100. Prg to illustrate the differences between int and double 101. Prg to show exception handling using try.. catch block 102. Prg to demonstrate how to use interface 103. Prg to print number triangle 104. Prg to demonstrate structure 105. Prg to test exception 106. Prg to count number of spaces and words in a entered string 107. Prg to demonstrate ref parameter 108. Prg to print a matrix table from 1 to 10 109. Prg to display 2 D array elements position in matrix form 110. Prg to count number of adult and children 111. Prg to print pascal triangle 112. Prg to demonstrate stringbuilder and its method 113. Prg to reverse a string 114. Prg for string sorting 115. Interview Question & Answer part 1 116. Interview Question & Answer part 2 117. Interview Question & Answer part 3 118. Interview Question & Answer part 4 119. Interview Question & Answer part 5 120. Interview Question & Answer part 6 121. Interview Question & Answer part 7 122. Interview Question & Answer part 8 123. Interview Question & Answer part 9 124. Interview Question & Answer part 10 125. Interview Question & Answer part 11 126. Interview Question & Answer part 12 127. Interview Question & Answer part 13 128. Interview Question & Answer part 14 129. Interview Question & Answer part 15
Pr.Pg Next Pg

C# Interview Questions and Answers Part 1

 

1. What's C# ?

  • C# is an object-oriented programming language developed by Microsoft Corporation.

  • C# is intended to be a simple, modern, general-purpose, object-oriented programming language. Its development team is led by Anders Hejlsberg. The most recent version is C# 5.0, which was released on August 15, 2012.

  • C# source code as well as those of other .NET languages is compiled into an intermediate byte code called Microsoft Intermediate Language. C# is primarily derived from the C, C++, and Java programming languages with some features of Microsoft's Visual Basic in the mix.

  • C# is used to develop applications for the Microsoft .NET environment. .NET offers an alternative to Java development. Microsoft's Visual Studio .NET development environment incorporates several different languages including VB.NET, C#, C++, and J# (Microsoft Java for .NET), all of which compile to the Common Language Runtime.

  • C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows use of various high-level languages to be used on different computer platforms and architectures.

 

 

2. Features of C#:

  • C# is the programming language that most directly reflects the underlying Common Language Infrastructure (CLI) Most of its intrinsic types correspond to value-types implemented by the CLI framework.

  • However, the language specification does not state the code generation requirements of the compiler that is, it does not state that a C# compiler must target a Common Language Runtime, or generate Common Intermediate Language (CIL), or generate any other specific format.

  • Theoretically, a C# compiler could generate machine code like traditional compilers of C++ or Fortran. Some notable features of C# is below:

  • C# supports strongly typed implicit variable declarations with the keyword var.

  • Meta programming via C# attributes is part of the language.

  • C# has strongly typed and verbose function pointer support via the keyword delegate.

  • C# offers Java-like synchronized method calls, via the attribute.

  • The C# languages does not allow for global variables or functions.

  • A C# namespace provides the same level of code isolation as a Java package or a C++ namespace.

  • Implicitly typed local variables.

 

3. What is an object?

  • An object is an instance of a class through which we access the methods of that class. “New” keyword is used to create an object.

  • A class that creates an object in memory will contain the information about the methods, variables and behavior of that class.

 

 

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

  • All these are access modifiers in C#. Public declared variables or methods are accessible anywhere in the application.

  • Static declared variables or methods are globally accessible without creating an instance of the class. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created.

  • And Void is a type modifier that states that the method or variable does not return any value.

 

 

5. If I return out of a try/finally in C#, does the code in the finally-clause run?

  • Yes. The code in the finally always runs. If you return out of the try block, or even if you do a goto out of the try, the finally block always runs:

 

using System;

class main

{

public static void Main()

{

try

{

Console.WriteLine(\"In Try block\");

return;

}

finally

{

Console.WriteLine(\"In Finally block\");

}

}

}

 

·         Both In Try block and In Finally block will be displayed. Whether the return is in the try block or after the try-finally block, performance is not affected either way. The compiler treats it as if the return were outside the try block anyway. If it’s a return without an expression (as it is above), the IL emitted is identical whether the return is inside or outside of the try. If the return has an expression, there’s an extra store/load of the value of the expression (since it has to be computed within the try block).

 

 

6.What are the types of comment in C# with examples?

i. Single line

 

Eg:

 

//This is a Single line comment

 

ii. Multiple line (/* */)

 

Eg:

 

/*This is a multiple line comment

We are in line 2

Last line of comment*/

 

iii. XML Comments (///).

 

Eg:

 

/// <summary>

/// Set error message for multilingual language.

/// </summary>

 

7.How does one compare strings in C#?

  • In the past, you had to call .ToString() on the strings when using the == or != operators to compare the strings’ values. That will still work, but the C# compiler now automatically compares the values instead of the references when the == or != operators are used on string types. If you actually do want to compare references, it can be done as follows: if ((object) str1 == (object) str2) { } Here’s an example showing how string compares work:

 

using System;

public class StringTest

{

public static void Main(string[] args)

{

Object nullObj = null; Object realObj = new StringTest();

int i = 10;

Console.WriteLine(\"Null Object is [\" + nullObj + \"]\n\"

+ \"Real Object is [\" + realObj + \"]\n\"

+ \"i is [\" + i + \"]\n\");

// Show string equality operators

string str1 = \"foo\";

string str2 = \"bar\";

string str3 = \"bar\";

Console.WriteLine(\"{0} == {1} ? {2}\", str1, str2, str1 == str2 );

Console.WriteLine(\"{0} == {1} ? {2}\", str2, str3, str2 == str3 );

}

}

 

Output:

Null Object is []

Real Object is [StringTest]

i is [10]

foo == bar ? False

bar == bar ? True

 

8.How do you specify a custom attribute for the entire assembly (rather than for a class)?

  • Global attributes must appear after any top-level using clauses and before the first type or namespace declarations. An example of this is as follows:

  • using System;

  • [assembly : MyAttributeClass] class X {}

  • Note that in an IDE-created project, by convention, these attributes are placed in AssemblyInfo.cs.

 

9.How do you mark a method obsolete?

  • [Obsolete] public int Foo() {...}

  • or

  • [Obsolete(\"This is a message describing why this method is obsolete\")] public int Foo() {...}

  • Note: The O in Obsolete is always capitalized.

 

10.How do you implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#?

  • You want the lock statement, which is the same as Monitor Enter/Exit:

  • lock(obj) { // code }

 

try {

CriticalSection.Enter(obj);

// code

}

finally

{

CriticalSection.Exit(obj);

}


Pr.Pg border                                              Next Pg