See Also: AvoidRepetitiveCastsRule Members
Example
foreach (object o in list) {
// first cast (is)
if (o is ICollection) {
// second cast (as) if item implements ICollection
Process (o as ICollection);
}
}
Example
foreach (object o in list) {
// a single cast (as) per item
ICollection c = (o as ICollection);
if (c != null) {
SingleCast (c);
}
}
Example
// first cast (is):
if (o is IDictionary) {
// second cast if item implements IDictionary:
Process ((IDictionary) o);
// first cast (is):
} else if (o is ICollection) {
// second cast if item implements ICollection:
Process ((ICollection) o);
}
Example
// a single cast (as) per item
IDictionary dict;
ICollection col;
if ((dict = o as IDictionary) != null) {
SingleCast (dict);
} else if ((col = o as ICollection) != null) {
SingleCast (col);
}