zero based lists became a habit

As a C# developer, you realy get acquainted to the fact that every list/array etc. is zero based.
In the early days of my development career, as a VB programmer, the fact that a list was zero or one based was a matter of choice! (yeah, that was fun :))
Anyway, in those days, you always asked yourself: is it zero based or one based.

As i said, these days i don’t… which give me a nice ‘unexpected behaviour’ in Sql Server where not all is zero based:

select CHARINDEX('.Net', 'aaa.Netbbb')
select CHARINDEX('.Net', '.Netbbb')
select CHARINDEX('.Net', 'aaa.N.etbbb')

Returns, in that order: 4, 1 and 0.
So if you  type this

"somestringvalue".IndexOf("sometext") >= 0

in c#, you must remove the “>” in Sql.

A minor difference, but in the edge cases of the unit test a large difference🙂

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