Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why doesn't this require a cast?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01026305
Message ID:
01026437
Vues:
19
Mike,

I believe the UsersDataSet.rb_UsersRow row is declaring the row as your row type for the purpose of the foreach loop. That is where the cast is occurring. If the objects contained in the Rows collection could not be cast to UsersDataSet.rb_UsersRow, an exception would be thrown (probably at compile time).

If you wanted to have to use an explicit cast inside the loop, the loop definition would be:
foreach (DataRow row in ds.Tables[tableName].Rows)
{
    UsersDataSet.rb_UsersRow myRow = (UsersDataSet.rb_UsersRow)row;
    ValidateAddress(myRow);
}
HTH,
Chad

>Hoping someone can help me understand what is happening here. Consider this code:
>
>public override bool CheckRulesHook(DataSet ds, string tableName)
>{
>	foreach (UsersDataSet.rb_UsersRow row in ds.Tables[tableName].Rows)
>	{
>		ValidateAddress(row);
>	}
>}
>
>Passed in to the method is a System.Data.DataSet, however, I can use my typed data row in the foreach without trouble. This seems strange because ds.Tables[tableName].Rows returns a DataRowCollection that is a collection of DataRows, not a collection of my typed rows.
>
>I would think I'd need to cast here, but it's not required. Why is this?
>
>Thanks,
>Mike
_________________________________
There are 2 types of people in the world:
    Those who need closure
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform