From: sameem on
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
From: Frans Bouma [C# MVP] on
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.ValueType) or it is a class itself ->
reference type, if it is a struct (e.g. Int32) or if it inherits from
System.ValueType, it is a value type. A struct automatically inherits
from System.ValueType, 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#)
------------------------------------------------------------------------
From: sameem on
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.ValueType) or it is a class itself ->
> reference type, if it is a struct (e.g. Int32) or if it inherits from
> System.ValueType, it is a value type. A struct automatically inherits
> from System.ValueType, 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#)
> ------------------------------------------------------------------------
>