Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you inherit StringBuilder in vb.net?

I want to add my own member to the StringBuilder class, but when I go to create it IntelliSense doesn't bring it up.

public class myStringBuilder()
    Inherits System.Text.[StringBuilder should be here]
    ....
end class

Is it even possible? thanks

like image 242
Anders Avatar asked Oct 07 '08 16:10

Anders


People also ask

What is StringBuilder in VB net?

In visual basic, StringBuilder is a class and it is useful to represent a mutable string of characters and it is an object of System. Text namespace. Like string in vb, we can use StringBuilder to create variables to hold any kind of text which is a sequential collection of characters based on our requirements.

Is StringBuilder reference type?

Both String and StringBuilder are reference type.

Why is StringBuilder sealed?

StringBuilder is sealed because it assembles strings, e.g. there should never be a reason to inherit from it because any use should be limited in scope. StringBuilder is not a replacement for string and should never be used that way.

What is the System string and System text StringBuilder classes?

The main difference is StringBuilder is Mutable whereas String is Immutable. String is immutable, Immutable means if you create string object then you cannot modify it and It always create new object of string type in memory. On the other hand, StringBuilder is mutable.


1 Answers

StringBuilder is NotInheritable (aka sealed in C#) so you cannot derive from it. You could try wrapping StringBuilder in your own class or consider using extension methods instead.

like image 144
Jeff Yates Avatar answered Sep 30 '22 05:09

Jeff Yates