This one has bothered me for some time. Here is the situation you have a simple array of strings and then you bind it to a DataGrid. What do you expect when the grid is rendered? Silly me I was expecting to see a bunch of strings. And what did I get, a grid with a single column containing a heading of Length and a list of values that represents the length of each string in the array.
What the heck is happening here?
Here is a code snippet that declares an array of String that is later bound to a DataGrid.
Dim s As String() = {"hey", "man", "where's", "my", "string"}
DataGridView1.DataSource = s.ToList
The DataGrid is displayed as
So where are the strings? Behind the covers .NET is using reflection to inspect the String object and searches for all properties that have no parameters. Each of these properties is then displayed in the DataGrid; and you guessed it the only parameter-less property the String object exposes is Length.
Guess the movie
Hey, what do you like, the leg or the wing, Henry? Or do you still go for the old hearts and lungs?