c# - Determining casting of an object -


i have code below

rssfeedreader rss = (rssfeedreader)this.parenttoolpane.selectedwebpart; 

my problem @ run time know if 'this.parenttoolpane.selectedwebpart' of type rssfeedreader or of type 'rsscountry'

how check object type , cast appropriatley?

many thanks,

you can this:

if (this.parenttoolpane.selectedwebpart rssfeedreader)     //... 

to check if of type. alternatively, can use 'as' use type, , null if not of type.

rssfeedreader reader = this.parenttoolpane.selectedwebpart rssfeedreader; if (reader != null) {     //... } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -