Tuesday, October 14, 2008


How do I declare inout arguments in C#?


The equivalent of inout in C# is ref. , as shown in the followingexample: public void MyMethod (ref String str1, out String str2)

{

...

}

When calling the method, it would be called like this: String s1;

String s2;

s1 = "Hello";

MyMethod(ref s1, out s2);

Console.WriteLine(s1);

Console.WriteLine(s2);

Notice that you need to specify ref when declaring the function and calling it.

Is there a way of specifying which block or loop to break out of when working with nested loops?

The easiest way is to use goto: using System;

class BreakExample

{

public static void Main(String[] args)

{

for(int i=0; i<3; j="0" j ="=">


What is the difference between const and static read-only?

The difference is that static read-only can be modified by the containing class, but const can never be modified and must be initialized to a compile time constant.

To expand on the static read-only case a bit, the containing class can only modify it:

-- in the variable declaration (through a variable initializer).

-- in the static constructor (instance constructors if it's not static).


What does the parameter Initial Catalog define inside Connection String?

The database name to connect to.


What is the difference between System.String and System.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.


What is the top .NET class that everything is derived from?

System.Object.


Can you allow class to be inherited, but prevent the method from being over-ridden?


Yes, just leave the class public and make the method sealed.

0 comments: