1. What is C#? C# is an object oriented, type safe and managed language that is compiled by .Net framework to generate Microsoft Intermediate Language. 2. What are the types of comment in C# with examples? Single lineEg: //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 3. Can multiple catch blocks be executed? No, Multiple catch blocks can’t be executed. Once the proper catch code executed, the control is transferred to the finally block and then the code that follows the finally block gets executed. 4. What is the difference between public, static and void? 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. Static member is by default not globally accessible it depends upon the type of access modified used. 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. 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. 6. Define Constructors? A constructor is a member function in a class that has the same name as its class. The constructor is automatically invoked whenever an object class is created. It constructs the values of data members while initializing the class. 7. What is Jagged Arrays? The array which has elements of type array is called jagged array. The elements can be of different dimensions and sizes. We can also call jagged array as Array of arrays. 8. What is the difference between ref & out parameters? An argument passed as ref must be initialized before passing to the method whereas out parameter needs not to be initialized before passing to a method. 9. What is the use of using statement in C#? The using block is used to obtain a resource and use it and then automatically dispose of when the execution of block completed. 10. What is serialization? When we want to transport an object through network then we must convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called Serialization. For an object to be serializable, it should implement I Serialize Interface. De-serialization is the reverse process of creating an object from a stream of bytes. 11. Explain the features of C#? Below are some of the features supported in C# – • Constructors and Destructors • Properties • Passing Parameters • Arrays • Main • XML Documentation and • Indexers 12. List some of the advantages of C#. Below are the advantages of C# – • Easy to learn • Object oriented • Component oriented • Part of .NET framework13. What are IDE’s provided by Microsoft for C# development? Below are the IDE’s used for C# development – • Visual Studio Express (VCE) • Visual Studio (VS) • Visual Web Developer14. Explain sealed class in C#? Sealed class is used to prevent the class from being inherited from other classes. So “sealed” modifier also can be used with methods to avoid the methods to override in the child classes. 15. Give an example of using sealed class in C#? Below is the sample code of sealed class in C# – class X {} sealed class Y: X {}Sealed methods –class A { protected virtual void First () {} protected virtual void Second () {} } class B: A { sealed protected override void First () {} protected override void Second () {} } If any class inherits from class “B” then method – “First” will not be overridable as this method is sealed in class B.16. List out the differences between Array and Array List in C#? • Array stores the values or elements of same data type but array list stores values of different datatypes. • Arrays will use the fixed length, but array list does not use fixed length like array. 17. Explain namespaces in C#? Namespaces are containers for the classes. We will use namespaces for grouping the related classes in C#. “Using” keyword can be used for using the namespace in another namespace. 18. Why to use keyword “const” in C#? Give an example. “Const” keyword is used for making an entity constant. We can’t reassign the value to constant. Eg: const string _name = “Test”; 19. What is the difference between “constant” and “read only” variables in C#? • “Const” keyword is used for making an entity constant. We cannot modify the value later in the code. Value assigning is mandatory to constant variables. • “read only” variable value can be changed during runtime and value to read only variables can be assigned in the constructor or at the time of declaration.20. Explain “static” keyword in C#? “Static” keyword can be used for declaring a static member. If the class is made static, then all the members of the class are also made static. If the variable is made static, then it will have a single instance and the value change is updated in this instance. 21. Why to use “finally” block in C#? “Finally,” block will be executed irrespective of exception. So, while executing the code in try block when exception is occurred, control is returned to catch block and at last “finally” block will be executed. So, closing connection to database / releasing the file handlers can be kept in “finally” block. 22. What is the difference between “finalize” and “finally” methods in C#? • Finalize – This method is used for garbage collection. So before destroying an object this method is called as part of clean up activity. • Finally – This method is used for executing the code irrespective of exception occurred or not. 23. What is the difference between “throw ex” and “throw” methods in C#? • “throw ex” will replace the stack trace of the exception with stack trace info of re throw point. • “throw” will preserve the original stack trace info.24. Can we have only “try” block without “catch” block in C#? Yes, we can have only try block without catch block, but we must have finally block.25. What’s the difference between the System. Array. Copy To () and System. Array. Clone ()? Using Clone () method, we create a new array object containing all the elements in the original array and using Copy To () method, all the elements of existing array copies into another existing array. Both the methods perform a shallow copy. 26. Write down the C# syntax to catch exception? To catch an exception, we use try catch blocks. Catch block can have parameter of system. Exception type. Eg: try { GetAllData (); } catch (Exception ex) { } In the above example, we can omit the parameter from catch statement. 27. What’s the difference between an interface and abstract class? Interfaces have all the methods having only declaration but no definition. In an abstract class, we can have some concrete methods. In an interface class, all the methods are public. An abstract class may have private methods. 28. What is the difference between Finalize () and Dispose () methods? Dispose () is called when we want for an object to release any unmanaged resources with them. On the other hand, finalize () is used for the same purpose but it doesn’t assure the garbage collection of an object. 29. What are circular references? Circular reference is situation in which two or more resources are interdependent on each other causes the lock condition and make the resources unusable. 30. What is an object pool in .NET? An object pool is a container having objects ready to be used. It tracks the object that is currently in use, total number of objects in the pool. This reduces the overhead of creating and re-creating objects. 31. List down the commonly used types of exceptions in .Net? Argument Exception, ArgumentNullException, ArgumentOutOfRangeException, Arithmetic Exception, DivideByZeroException, Overflow Exception, IndexOutOfRangeException, InvalidCastException, InvalidOperationException, IOEndOfStreamException, Null Reference Exception, Out of Memory Exception, Stack Overflow Exception etc. 32. Explain access modifier – “protected internal” in C#? “protected internal” can be accessed in the same assembly and the child classes can also access these methods. 33. In try block if we add return statement whether finally block is executed in C#? Yes. Finally, block will still be executed in presence of return statement in try block. 34. What you mean by inner exception in C#? Inner exception is a property of exception class which will give you a brief insight of the exception i.e., parent exception and child exception details. 35. Explain String Builder class in C#? This will represent the mutable string of characters and this class cannot be inherited. It allows us to Insert, Remove, Append and Replace the characters. “To String ()” method can be used for the final string obtained from String Builder. For example, String Builder Test Builder = new String Builder(“Hello”); TestBuilder.Remove(2, 3); // result – “He” TestBuilder.Insert(2, “lp”); // result – “Help” TestBuilder.Replace(‘l’, ‘a’); // result – “Heap”36. What is the difference between “String Builder” and “String” in C#? • String Builder is mutable, which means once object for string builder is created, it later be modified either using Append, Remove or Replace. • String is immutable, and it means we cannot modify the string object and will always create new object in memory of string type. 37. How we can sort the array elements in descending order in C#? “Sort ()” method is used with “Reverse ()” to sort the array in descending order.38. Explain Generics in C#? Generics in c# is used to make the code reusable and which intern decreases the code redundancy and increases the performance and type safety. Namespace – “System. Collections. Generic” is available in C# and this should be used over “System. Collections” types.39. How to use nullable types in .Net? Value types can take either their normal values or a null value. Such types are called nullable types. Int? someID = null; If (someID.HasVAlue) { } 40. How we can create an array with non-default values? We can create an array with non-default values using Enumerable. Repeat. 41. What is difference between is and as operators in c#? “is” operator is used to check the compatibility of an object with a given type and it returns the result as Boolean. “as” operator is used for casting of object to a type or a class. 42. What’s a multicast delegate? A delegate having multiple handlers assigned to it is called multicast delegate. Each handler is assigned to a method. 43. What are indexers in C# .NET? Indexers are known as smart arrays in C#. It allows the instances of a class to be indexed in the same way as array. Eg: public int this [int index] // Indexer declaration 44. What are C# attributes and its significance? C# provides developers a way to define declarative tags on certain entities e.g. Class, method etc. are called attributes. The attribute’s information can be retrieved at runtime using Reflection. 45. How to implement singleton design pattern in C#? In singleton pattern, a class can only have one instance and provides access point to it globally. Eg: Public sealed class Singleton { Private static read only Singleton _instance = new Singleton (); } 46. What is the difference between direct cast and ctype? Direct Cast is used to convert the type of an object that requires the run-time type to be the same as the specified type in Direct Cast. Ctype is used for conversion where the conversion is defined between the expression and the type. 47. Is C# code is managed or unmanaged code? C# is managed code because Common language runtime can compile C# code to Intermediate language. 48. What are delegates? Delegates are same are function pointers in C++, but the only difference is that they are type safe unlike function pointers. Delegates are required because they can be used to write much more generic type safe functions. 49. How do you inherit a class into other class in C#? Colon is used as inheritance operator in C#. Just place a colon and then the class name. public class Derived Class: Base Class 51. What is the difference between method overriding and method overloading? In method overriding, we change the method definition in the derived class that changes the method behavior. Method overloading is creating a method with the same name within the same class having different signatures. Pernytha roy SRIEIT]]>

Write A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.