Reputation: 35
What is use of (Validation.Errors)[0].ErrorContent and also tell the significance of [0] in this context ?
Upvotes: 2
Views: 452
Reputation: 36287
Validation.Errors
is an array and you get the first element in that arrah/list by using "index" 0. To get a certain index in an array, you use [ ]
.
In this case you basicly say:
Give me the first record of the Validation.Errors
Validation.Errors
Gets the collection of all active ValidationError objects on the bound element.
You could get all validation errors by using the enumerator like this:
foreach(var error in Validation.Errors){}
In case an Array is Empty, there wont be any elements at [0]
thus throwing an IndexOutOfBoundException
.
Upvotes: 2