If Anybody Cares, Why???

For my first code-related post, here’s a fairly esoteric pain in the ass.

Why is the .NET function string.EndsWith(char) an internal function that you can’t use in your own code?? The reason I find this particularly annoying is that the Path class has some nice features to make your code platform-independent, such as Path.DirectorySeparatorChar – which is defined as a char. So you’d expect to be able to write:

if (myPath.EndsWith(Path.DirectorySeparatorChar)) { // do stuff…

But you can’t! You have to write:

if (myPath.EndsWith(Path.DirectorySeparatorChar.ToString())) { // do stuff…

In other words, you have to convert the char to a string before passing it to EndsWith. Not a big gripe, but it’s irritating since a quick peek with the excellent .NET Reflector shows that there exists

internal string.EndsWith(char)

Because it’s declared as internal, though, you can’t use it from your own code.

Am I right to be irritated or am I missing something?

Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s