private const string s = "" yields null?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Miha Markic

    private const string s = "" yields null?

    Hi,

    Did anybody notice that the following declaration of a member const

    public class Tubo
    {
    private string const def = "";
    }

    is alyways null instead of empty string ("")?

    Is this a bug or feature or something else?

    Thanks,
    Miha
    miham at spin dot si


  • Miha Markic

    #2
    Re: private const string s = "" yields null?

    Duh, it is only the debugger reporting it as null.
    It is correctly set to "".

    Miha

    "Miha Markic" <msdn@spin.si > wrote in message
    news:usKfEZjlDH A.2328@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Hi,
    >
    > Did anybody notice that the following declaration of a member const
    >
    > public class Tubo
    > {
    > private string const def = "";
    > }
    >
    > is alyways null instead of empty string ("")?
    >
    > Is this a bug or feature or something else?
    >
    > Thanks,
    > Miha
    > miham at spin dot si
    >
    >[/color]


    Comment

    • William Ryan

      #3
      Re: private const string s = &quot;&quot; yields null?

      string.Empty is the preferred way to do it but "" will work as well
      "Miha Markic" <msdn@spin.si > wrote in message
      news:enyfScjlDH A.2404@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Duh, it is only the debugger reporting it as null.
      > It is correctly set to "".
      >
      > Miha
      >
      > "Miha Markic" <msdn@spin.si > wrote in message
      > news:usKfEZjlDH A.2328@TK2MSFTN GP10.phx.gbl...[color=green]
      > > Hi,
      > >
      > > Did anybody notice that the following declaration of a member const
      > >
      > > public class Tubo
      > > {
      > > private string const def = "";
      > > }
      > >
      > > is alyways null instead of empty string ("")?
      > >
      > > Is this a bug or feature or something else?
      > >
      > > Thanks,
      > > Miha
      > > miham at spin dot si
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Miha Markic

        #4
        Re: private const string s = &quot;&quot; yields null?

        Hi William,

        string.Empty won't work for constant declaration.

        Miha

        "William Ryan" <dotnetguru@nos pam.comcast.net > wrote in message
        news:Oe%23xdcll DHA.1708@TK2MSF TNGP12.phx.gbl. ..[color=blue]
        > string.Empty is the preferred way to do it but "" will work as well
        > "Miha Markic" <msdn@spin.si > wrote in message
        > news:enyfScjlDH A.2404@TK2MSFTN GP12.phx.gbl...[color=green]
        > > Duh, it is only the debugger reporting it as null.
        > > It is correctly set to "".
        > >
        > > Miha
        > >
        > > "Miha Markic" <msdn@spin.si > wrote in message
        > > news:usKfEZjlDH A.2328@TK2MSFTN GP10.phx.gbl...[color=darkred]
        > > > Hi,
        > > >
        > > > Did anybody notice that the following declaration of a member const
        > > >
        > > > public class Tubo
        > > > {
        > > > private string const def = "";
        > > > }
        > > >
        > > > is alyways null instead of empty string ("")?
        > > >
        > > > Is this a bug or feature or something else?
        > > >
        > > > Thanks,
        > > > Miha
        > > > miham at spin dot si
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...