Re: Array conversion question
- From: "Christiaan van Bergen" <cvanbergen@xxxxxxxxxx>
- Date: Tue, 11 Oct 2005 13:45:28 +0200
That's it Scott,
Even better :-)
Christiaan
"Scott Coonce" <sdcoonce@xxxxxxxxxxxxxxxxx> schreef in bericht
news:u9xa7glzFHA.3772@xxxxxxxxxxxxxxxxxxxxxxx
> Try the following (or something like it, untested code follows):
>
>
> MyType[] buf = new MyType[somearraylist.Count];
> somearraylist.CopyTo(buf);
>
> I think does it.
>
> Scott
>
>
> "Christiaan van Bergen" <cvanbergen@xxxxxxxxxx> wrote in message
> news:dig4lp$sm9$1@xxxxxxxxxxxxxxxxxx
>> Hi Pavils,
>>
>> A bit crude, I must admit.......(this is probably your ineffective way)
>>
>> MyType[] Result = new MyType[output.Count];
>> for(int x=0;x<output.Count;x++)
>> {
>> Result[x] = output[x] as MyType;
>> }
>>
>> Cheers
>> Christiaan
>>
>> "Pavils Jurjans" <pavils@xxxxxxxxxxxxxxx> schreef in bericht
>> news:O5whC6kzFHA.2212@xxxxxxxxxxxxxxxxxxxxxxx
>>> Hello,
>>>
>>> I think this is classical problem, but I can't figure out how to do it
>>> in most right way (I know ineffective way though ;)
>>>
>>> So, I have this method that does some database work and has to return an
>>> array of custom type, let's say
>>>
>>> public MyType[] MyMethod(params)
>>> {
>>> ArrayList output = new ArrayList();
>>> }
>>>
>>> Since the return array can be of different sizes, dependinf on
>>> parameters, I use standard ArrayList within the body of MyMethod to
>>> gather the results. Whenever a new element is added, something like this
>>> is executed:
>>>
>>> MyType element = new MyType();
>>> // Some element data populating code
>>> output.Add(element);
>>>
>>> Now, when I need to return the output, I need to do some kind of
>>> chemistry so that it is returned as correct MyType[]. What is the most
>>> appropriate way?
>>>
>>> Thanks,
>>>
>>> Pavils Jurjans
>>>
>>
>>
>
>
.
- Follow-Ups:
- Re: Array conversion question
- From: Richard Blewett [DevelopMentor]
- Re: Array conversion question
- References:
- Re: Array conversion question
- From: Scott Coonce
- Re: Array conversion question
- Prev by Date: Re: ReadLine and WriteLine
- Next by Date: Starter KIT Problem
- Previous by thread: Re: Array conversion question
- Next by thread: Re: Array conversion question
- Index(es):
Relevant Pages
|