Re: I think C# is forcing us to write more (redundant) code



Bob Powell [MVP] <bob@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Creation and assignment of variables is essentially the same for VB and C#.
> Value types are assigned their normal default values. For example you don't
> have to explicitly write:
>
> int x = new int(12);
>
> and if you just use "int x;" then x contains zero.
>
> Reference types are assigned null by the framework too.

No, that's not true for local variables. Local variables aren't
assigned to anything by default, and can't be read until they've been
definitely assigned.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: #define preprocessor
    ... an int in the compiled code wherever it's used. ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why enums can convert to IntPtr?
    ... Not true - it also occurs with interfaces. ... int x = 5; ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DatGrid.DataSource
    ... > inventario) but a want sent a val string and not a ... > int, how I do that ... Please delete "REMOVE" from the e-mail address when replying. ... Prev by Date: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Newbie question on creating class based on Int32
    ... > come up with my own class named int, but I want a class that I could replace ... > int with that "looks and feels" like an int type so I could replace all int i ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.general)
  • Re: Readonly locals?
    ... int _p; ... A write-once property is much less useful, because the implementer of the class still doesn't know exactly when the property will be written to, so the immutability is something you can hardly count on. ... Transforming the code to a new form by introducing or eliminating local variables is a lot safer if you can guarantee that a variable isn't assigned to halfway down the method, or modified by passing it as a ref parameter somewhere. ... But a class doesn't set rules or break them, the programmer does. ...
    (microsoft.public.dotnet.languages.csharp)

Loading