1. Differences between Array and ArrayList in C#?
Array stores the values or elements of same data type but arraylist stores values of different datatypes.Arrays will use the fixed length but arraylist does not uses fixed length like array.
2. Difference between StringBuilder and string.
StringBuilder is mutable.
StringBuilder one copy of memory created.
Stringbuilder manipulate content multiple times.
StringBuilder is gives better performance
StringBuilder Once object created you can later modify Append Remove or Replace
StringBuilder performs faster than string when appending multiple string values.
String is immutable.
string is create multiple copies of memory
string is create instances multiple times
String once object create then after you can not modify the string object and will always create new object in memory of string type.
3. What is difference between Prase and TryParse.
Parse throws an exception if it cannot parse the value, whereas TryParse returns a bool indicating whether it succeeded.
In fact the way it is most likely implemented is that internally the Parse method will call TryParse and then throw an exception if it returns false .
4. What is Abstract Class.
Abstract class cannot create object.
An abstract class can never be sealed or static.
An abstract class can have abstract and non abstract methods.
The abstract keyword use with class, methods, properties, indexers and events.
An abstract method cannot be static or private.
Abstract class cannot inherit more than one class.
5. What is difference between is and as operators.
Is Operator is used to Check the Compatibility of an Object with a given Type and it returns the result as a Boolean i.e. True Or False.
"as" operator is used for casting of object to a type or a class.
6. What is difference between Out and Ref.
Out and ref helps to pass by reference.
Ref is two way from caller to callee and back.
Out is one way it sends data back from callee to caller and data from caller is discarded.
7. What is Difference between ToString() and Convert.ToString().
Convert.ToString() handle null
ToString() function does not handle null
8. What is Difference between == and EqualTo().
== compare if the object reference are same.
.EqualTo() method compares if the contents are same.
object o="abc";
object o1=new string("abc");
Console.WriteLine(o==o1);
Console.WriteLine(o.Equals(o1));
9. Difference between String and string
There is no difference String is the Class name and string is the alias.
10. What is Generics.
It helps you in code reuse, performance and type safety.
You can create your own generic classes, methods, interfaces and delegates.
You can create generic collection classes.
11. What is difference between Checked and unchecked.
The checked operator evaluates a block of code in a checked context and enforces overflow through an exception if an overflow occurs.
The checked operator evaluates a block of code in an unchecked context and does not through overflow exception if an overflow occurs.
12. What is difference between Conversion & Casting.
Conversion-Converts from one data type to other data type using the convert class.
Casting-Convert from one data type to other data type by defining the data type.
13. What is difference between Implicit and Explicit.
Implicit Casting-No need to define to cast from where to where no data loss.
Explicit casting-Need to define to cast from where to where . Data loss can happen
14. What is Polymorphism.
Static or compile-time polymorphism (method overloading and operator overloading).
overloads must be different in their signature, which means the name and the number and type of parameters.
Dynamic or runtime polymorphism is method overriding and inherited from base class
it is decided at run-time.
Using the "new" keyword, we can hide the base class member.
16. What is Inheritance.
It allow code reduce.
Code reduce can reduce time and error.
Inheritance derived class inherits from parent class.
C# support only single class inheritance.
C# support multiple interface inheritance.
Base class are automatically instantiated before derive class.
Parent class constructor execute before child class constructor.
17. Difference between abstract class and interface.
Abstract classess can have implementation for any of its Method.
Interface can't have implementation for any of its method
Abstract classes can have field.
Interface cant have field.
Abstract class can inherit from another abstract class or another interface.
An interface can inherit from another interface only cannot inherit from an abstract class
Abstract class member can have access modifier where as interface member cannot have access modifier.
A class can inherit from multiple interfaces at the same time. whereas a class cannot inherit from multiple classes at the same time.
Question and Answer.
*********What is interface?By default interface is? :internal
Can we have access modifier in interface:no
Can we have variable in interface:no
Can we create instance of interface:no
Can we create construction in interface:no
can we declare properties in interface:yes
Can interface inherit another interface?:Yes
Can interface inherit class:No
Interface by default are method all:Public
No comments:
Post a Comment