is it ok to do this... and generics

From: sparkles (user_at_site.com)
Date: 03/30/05


Date: Tue, 29 Mar 2005 22:06:45 GMT

sorry about the subject - i'm not quite sure what it is i'm asking is called

is there anything wrong with doing this...?

ArrayList al = new ArrayList();
al.add(new MyClass(1, 2, 3, 4)); <-----

or is it better to do this?

ArrayList al = new ArrayList();
MyClass class = MyClass(1, 2, 3, 4);
al.add(class);

also if the arraylist is instantiated using generics as such

ArrayList<MyClass> al = new ArrayList<MyClass>();

does that mean that al.get() will return a MyClass or do i still have to
cast it?

TIA



Relevant Pages

  • Re: Why does this object need to be cast?
    ... Having just attended an all day 'generics' education day, ... why do I need to cast to comboboxes? ... >> know that this is an object of type combobox? ... > Example with cast operators on System.Byte and System.Int32: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: What about turbos?
    ... In Delphi.NET TSomeClasssatisfies a compile time check but ALSO ... Type checking with a cast is at runtime. ... As maybe - I haven't really thought about the .NET generics implementation as ... ensure that they get that type (or NIL as you pointed out). ...
    (borland.public.delphi.non-technical)
  • Re: Casting generic collections & inheritance
    ... think the problem is that people who are new to generics (such as ... " which goes back to the English grouping problem. ... >> just a simple cast from Farmer to Person. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Strange requirement of IConvertible from XML serializer
    ... I am trying to extract the essential part of the code that would reproduce ... MyClass, but the second fails. ... >> to cast serialized class from object to a type. ... I check in debugger that the type is correctly loaded. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: A simple cast.
    ... you can cast it to PVOID or only store it under the correct pointer type ... >> I have a class MyClass, and I have instantiated it in the variable ... > CoolFunction *is not virtual*, you can use the following syntax... ... > Anti-spam: my real e-mail address has no digits; ...
    (microsoft.public.win32.programmer.kernel)