Home » Posts tagged "string"

String and StringBuilder

A couple of weeks ago, we discussed Value types and Reference types where we said that a reference type points to the value it represents and a value type is the value it represents.

This has implications when we work with the assignment operator because when you assign a reference type and change the content of what it is pointing to, both variables get changed because they are both pointing to the same location in memory.  If you do this with a value type, only the one you change sees the change because you are working with a copy.

Continue reading “String and StringBuilder”

.Net String Pool – Not Just For The Compiler

B03B0055 On Monday, I was corrected in my assertion that creating multiple empty strings would create multiple objects.  Turns out the compiler automatically puts all of the strings that are exactly the same in a “string pool” so that there is only ever one empty string in the entire application you’ve created.

Duh! I should have known this, or at least I should have expected that this was so since it has been true with every other compiled language I’ve worked with.

But what I didn’t know and couldn’t expect is that we can make use of this string pool programmatically as well.

Continue reading “.Net String Pool – Not Just For The Compiler”

C# “” better than string.Empty?

arct-013I recently read an article that argued that “” is “Better than String.Empty”

The argument is that since string.Empty doesn’t work in all situations, we should not use it at all.  He further argues that since the compiler can’t optimize code using string.Empty, the performance gains we might lose due to our lack of this optimization further supports the argument that we should not use it at all.

But at what price?

Continue reading “C# “” better than string.Empty?”

VB.NET – Char from String with Option Strict

G04B0079 So here’s the question:

I’m using String.Split() and need to pass in a Char or a Char array as the parameter.  If I pass in a string String.Split(“/”) I get an error “Option Strict On disallows implicit conversions from ‘String’ to ‘Char’.”

Obviously, the easiest way to fix this would be to turn off Option Strict, but I would prefer to keep it on.  So how do I pass in the Char instead of a String in this situation?”

Continue reading “VB.NET – Char from String with Option Strict”