Prev: Application Domain
Next: Help Break-In Mockina
From: shapper on 16 May 2010 18:07 Hello, Is there a difference between using: controller = ObjectFactory.GetInstance(controllerType) as IController; Or controller = (IController)ObjectFactory.GetInstance(controllerType); I see the first one with a VB similar sintax and the second one as C#. But C# accepts both ... How should I use it? Thank You, Miguel
From: Arne Vajhøj on 16 May 2010 18:17 On 16-05-2010 18:07, shapper wrote: > Is there a difference between using: > controller = ObjectFactory.GetInstance(controllerType) as > IController; > > Or > controller = (IController)ObjectFactory.GetInstance(controllerType); > > I see the first one with a VB similar sintax and the second one as C#. > But C# accepts both ... > > How should I use it? The first return null if cast not possible the last throw an exception if cast not possible. In most cases I will recommend the last, because it gives much easier to find errors. Arne
From: Jackie on 16 May 2010 18:15 On 5/17/2010 00:07, shapper wrote: > Hello, > > Is there a difference between using: > controller = ObjectFactory.GetInstance(controllerType) as > IController; > > Or > controller = (IController)ObjectFactory.GetInstance(controllerType); > > I see the first one with a VB similar sintax and the second one as C#. > But C# accepts both ... > > How should I use it? > > Thank You, > Miguel The first one will simply return null and not throw an exception if the cast fails, while the other one will.
From: shapper on 17 May 2010 19:19 On May 16, 11:15 pm, Jackie <Jac...(a)an.on> wrote: > On 5/17/2010 00:07, shapper wrote: > > > > > Hello, > > > Is there a difference between using: > > controller = ObjectFactory.GetInstance(controllerType) as > > IController; > > > Or > > controller = (IController)ObjectFactory.GetInstance(controllerType); > > > I see the first one with a VB similar sintax and the second one as C#. > > But C# accepts both ... > > > How should I use it? > > > Thank You, > > Miguel > > The first one will simply return null and not throw an exception if the > cast fails, while the other one will. Thank you for the clarification
|
Pages: 1 Prev: Application Domain Next: Help Break-In Mockina |