Is StringBuilder class Value type?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?c2FtZWVt?=

    Is StringBuilder class Value type?

    Dear All

    up to my level that I have known the StringBuilder class is reference type.
    Someone telling that StringBuilder class is Value type.

    Hence I want to clarify which is right? and how?

    Regards
    Sam
  • Frans Bouma [C# MVP]

    #2
    Re: Is StringBuilder class Value type?

    sameem wrote:
    Dear All
    >
    up to my level that I have known the StringBuilder class is reference type.
    Someone telling that StringBuilder class is Value type.
    >
    Hence I want to clarify which is right? and how?
    It's a reference type. String is also a reference type (though it
    behaves like a valuetype). To determine if a type is a valuetype or a
    reference type, you can look into the MSDN, lookup the type's
    documentation page, and you can see if it inherits from a class (except
    when it inherits from System.ValueTyp e) or it is a class itself ->
    reference type, if it is a struct (e.g. Int32) or if it inherits from
    System.ValueTyp e, it is a value type. A struct automatically inherits
    from System.ValueTyp e, see reflector on System.Int32 for example.

    In general, a type which is mutable is likely to be a reference type,
    or at least should be a reference type, according to MS guidelines.

    So first thing to check: documentation.

    FB

    --
    ------------------------------------------------------------------------
    Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
    LLBLGen Pro website: http://www.llblgen.com
    My .NET blog: http://weblogs.asp.net/fbouma
    Microsoft MVP (C#)
    ------------------------------------------------------------------------

    Comment

    • =?Utf-8?B?c2FtZWVt?=

      #3
      Re: Is StringBuilder class Value type?

      Thanks a lot.

      "Frans Bouma [C# MVP]" wrote:
      sameem wrote:
      Dear All

      up to my level that I have known the StringBuilder class is reference type.
      Someone telling that StringBuilder class is Value type.

      Hence I want to clarify which is right? and how?
      >
      It's a reference type. String is also a reference type (though it
      behaves like a valuetype). To determine if a type is a valuetype or a
      reference type, you can look into the MSDN, lookup the type's
      documentation page, and you can see if it inherits from a class (except
      when it inherits from System.ValueTyp e) or it is a class itself ->
      reference type, if it is a struct (e.g. Int32) or if it inherits from
      System.ValueTyp e, it is a value type. A struct automatically inherits
      from System.ValueTyp e, see reflector on System.Int32 for example.
      >
      In general, a type which is mutable is likely to be a reference type,
      or at least should be a reference type, according to MS guidelines.
      >
      So first thing to check: documentation.
      >
      FB
      >
      --
      ------------------------------------------------------------------------
      Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
      LLBLGen Pro website: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ------------------------------------------------------------------------
      >

      Comment

      Working...