|
|
Choosing A Webhost: |
Re: Casting question: msg#00168windows.devel.dotnet.cx
> public static void Test() > { > B[] b = (B[])Gimme(5); // invalid cast > } I'm guessing that's because B is derived from A. All B's are A's, but not all A's are B's. > public static A[] Gimme(int i) > { > A[] a = new A[i]; > return a; > } This method creates A's. None of the created objects have the extra information necessary to identify them as B's; they are created as A's. The reverse, however, should work (WARNING -- Outlook compiler in use): public class A { } public class B : A { } public class Tester { public static B[] Gimme(int i) { B[] b = new B[i]; return b; } public static void Test() { A[] a = (A[])Gimme(5); } } ------------------------------------ Magenic Technologies Jeff Ferguson Consulting Manager ------------------------------------ =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Casting question, Eddie Lascu |
|---|---|
| Next by Date: | Re: Casting question, Rick Taylor |
| Previous by Thread: | Re: Casting question, Eddie Lascu |
| Next by Thread: | Re: Casting question, Rick Taylor |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |