Q.Difference between Classes and Structures?
1. Classes support inheritance. Structs does't support inheritance polymorphism, but implements an interface.
2. Class is permitted to declare a destructor.But a struct is not permitted to declare a destructor.
3. Classes must be instantiated using the new operator. But structs can be instantiated without using the new operator.
4. Classes are reference type, a class variable can be assigned null.
But we cannot assign null to a struct variable, since structs are value type.
struct AStruct
{
int aField;
}
class AClass
{
int aField;
}
class MainClass
{
public static void Main()
{
AClass b = null; // No error.
AStruct s = null;
// Error [ Cannot convert null to 'AStruct'because it is a value type ].
}
}
Classes can have parameterless constructors. But structs cannot have parameterless constructors.
class MyClass
{
int myVar = 10;
public MyClass( ) // no syntax error.
{
// statements
}
}
struct MyStruct
{
int myVar;
public MyStruct( ) // syntax error.
{
// statements
}
What's the difference between System.String and System.Text.StringBuilder classes?
System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
When we use the "String" object to concatenate two strings, the first string is combined to the other string by creating a new copy in the memory as a string object, and then the old string is deleted. This process is a little long. Hence we say "Strings are immutable".
When we make use of the "StringBuilder" object, the Append method is used. This means, an insertion is done on the existing string. Operation on StringBuilder object is faster than String operations, as the copy is done to the same location. Usage of StringBuilder is more efficient in case large amounts of string manipulations have to be performed.
What does the term immutable mean?
The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
what is difference between int.Parse("123") and Convert.ToInt32("456")?
I know the int.Parse("123") will result in an int of 123, but what happens with a null? I believe it give a null exception (seems like I get either NullArgumentException or ArgumentNullException).
When I do the Convert.ToInt32(Application["PageCounter"]), the first time (it's
null), the method converts it to zero.
Q: what is the difference between DLL and EXE?
1. Fullname of .exe is Extensible Execute File.
2. An EXE can run independently.
3. EXE is an out-process file.
1. Fullname of .dll is Dynamic Link Liberary
2. DLL will run within an EXE.
3. DLL is an in-process file.
Q : What is the difference between Dispose() and Finalize() ?
When the .NET framework instantiates an object, it allocates memory for that object on the managed heap. The object remains on the heap until it's no longer referenced by any active code, at which point the memory it's using is "garbage," ready for memory deallocation by the .NET Garbage Collector (GC). Before the GC deallocates the memory, the framework calls the object's Finalize() method, but developers are responsible for calling the Dispose() method.
The two methods are not equivalent. Even though both methods perform object cleanup, there are distinct differences between them.
The .NET garbage collector manages the memory of managed objects (native .NET objects) but it does not manage, nor is it directly able to clean up unmanaged resources. Managed resources are those that are cleaned up implicitly by the garbage collector. You do not have to write code to release such resources explicitly. In contrast, you must clean up unmanaged resources (file handles, database collections, etc.) explicitly in your code.
There are situations when you might need to allocate memory for unmanaged resources from managed code. As an example, suppose you have to open a database connection from within a class. The database connection instance is an unmanaged resource encapsulated within this class and should be released as soon as you are done with it. In such cases, you'll need to free the memory occupied by the unmanaged resources explicitly, because the GC doesn't free them implicitly. For this we will use dispose method provided by the IDisposable Interface.
Q: What is type safety all about?
A: Type safety is about increasing the opportunities for the compiler to detect your coding errors. If you use interfaces instead of delegates the compiler will have more opportunities to detect your coding errors.
Q: What other differences exist between delegates and interfaces?
A: Interfaces carry semantics, and when a programmer implements an interface, he is typically well aware of that semantics. When you try to invoke a particular method via an interface, you can be fairly certain that if you succeed, the semantics of that method is what you expect. For that reason, using interfaces is essentially doing a check for semantic correctness on some level.
Delegates, on the other hand, by only verifying the method signature, make the programmer responsible for ensuring that the semantics of the method is compatible. The semantics may cover not only the meaning of the arguments and return value (some times even the order of the arguments if they are of the same type), the ranges of the arguments, but also an invocation order when multiple methods are concerned. Hence, in a sufficiently large program there is plenty of margin to make an error when different programmers are not forced to comply with a uniform semantics (as they would be if interfaces were used).
What is difference between debug and release?
Debug and Release are different configurations for building your project.
You generally use the Debug mode for debugging your project, and the Release mode for the final build for end users.
The Debug mode does not optimize the binary it produces (as optimizations can greatly complicate debugging), and generates additional data to aid debugging.
The Release mode enables optimizations and generates less (or no) extra debug data.
What?s different about switch statements in C#?
1. It does not allow automatic fallthrough in non-empty cases.
2. The order of the default case does not manner. It need not have to be the last case.
3. Unlike C++ or Java, C#'s switch allows a variable of type string to be tested.
4. Use of goto statement to switch from one case label to another.
Q. What is Remoting?
An architecture designed to simplify communication between objects living in different application domains whether on the same computer or not.
Q. String functions?
http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingWithStringsP311232005021723AM/WorkingWithString
Sunday, March 23, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment