5
Contributors
9
Replies
11
Views
6 Years
Discussion Span
Last Post by Farhad.idrees
Featured Replies
  • 1
    Narue 5,707   6 Years Ago

    It depends on the type and scope of the variable. Can you be more specific? Read More

  • 1

    int types are always initialized (to zero). You can check if a string type is null ([icode]if (myString == null) { // Not initialized[/icode]. In general, a null reference means the variable doesn't have an object. Read More

  • 1
    Narue 5,707   6 Years Ago

    [B]>int types are always initialized (to zero).[/B] This misconception is why I asked for a more specific question. As an example, local variables are not automatically initialized, which means there's no way to check them without relying on compiler warnings/errors. [code] static void Main(string[] args) { int i; // Not … Read More

1

int types are always initialized (to zero). You can check if a string type is null ( if (myString == null) { // Not initialized .

In general, a null reference means the variable doesn't have an object.

1

>int types are always initialized (to zero).
This misconception is why I asked for a more specific question. As an example, local variables are not automatically initialized, which means there's no way to check them without relying on compiler warnings/errors.

static void Main(string[] args)
{
    int i; // Not initialized (value type)
    string s; // Not initialized (reference type)

    // ...
}
0

Also, you should use the static String.IsNullOrEmpty method to check for uninitialised strings.

0

Also, you should use the static String.IsNullOrEmpty method to check for uninitialised strings.

but what is benefit of using static string?

1

I meant the static method of the String class IsNullOrEmpty , not that the string itself is static. This static method checks whether the string is unitialised or initialised to String.Empty .

Comments
1

I meant the static method of the String class IsNullOrEmpty , not that the string itself is static. This static method checks whether the string is unitialised or initialised to String.Empty .

hmm got it..

Comments
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.