Alex Rivera | Logout

using the 'is' keyword in a switch in c#

Asked 2008-10-21T21:52:16.177
31

I'm currently adding some new extended classes to this code:

foreach (BaseType b in CollectionOfExtendedTypes) {
  if (b is ExtendedType1) {
    ((ExtendedType1) b).foo = this;

  }
  else if (b is ExtendedType2) {
    ((ExtenedType2) b).foo = this;

  } 
  else {
    b.foo = this;

  }
}

and was curious if there is a way to use the is keyword functionality in a switch statement?

Edit
Report

1 Answer

5
answered 2008-10-21T21:54:46.687

Your Answer