What is the difference between test.Rows[0]
and test.Rows[test.Rows.Count - 1]
if rows is a collection in a datatable.For example
if count =o or count = -1 what will be the situation here
My intention was to determine the last value in that collection.If no value is there in that collection will it make problems Previously test.Rows[0]["Level"] is always giving 18 digit number but when i made in to test.Rows[test.Rows.Count - 1]["version"] it is giving correct one
SO finally my question is if count = 1 will both statement test.Rows[0] and test.Rows[test.Rows.Count - 1] will be equal or what is the situation will both statement are equal I debugged code ,if i go with test.Rows[0]["Level"] it always showing one 18 digit constant value,why it is showing like that.This Test is开发者_JS百科 a datatable in .xsd file where i can see one and only 'Level' row
In a zero-based collection / array / list, etc; item 0
and item count - 1
are the first and last items respectively.
For example if count =o
If the collection does not have any items, either of the above will usually result in an out-of-range exception. So... don't do that. Check the size first.
or count = -1
If the count is -1, you have bigger problems - like, you broke the universe
You might also look at LINQ's FirstOrDefault()
/ LastOrDefault()
etc (both have special checking for typed lists to minimise pain - but I don't know if .Rows
is technically a typed list (IList<T>
) - I suspect not); but access via an indexer is convenient and fast.
精彩评论