Re: Array conversion question



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
>>>
>>
>>
>
>


.



Relevant Pages

  • rs232...
    ... Hello Scott and everyone else who will read this post. ... //immediatelly assigned to this array. ... // from the rs232 port), ... I thank Scott and all members of the news groups that have helped me on the ...
    (microsoft.public.vc.language)
  • Re: [Question:]How to split one file into 3/4 using fortran?
    ... "Gary L. Scott" wrote: ... I don't know how to open the array to store the ... > Now if you know the EXACT format (exact number of comments, ... > Liberty is a well armed sheep contesting the vote. ...
    (comp.lang.fortran)
  • Re: Passing arrays ByVal vs ByRef
    ... If you pass a reference type (such as an Array), you get a copy of the reference, not the type and this explains why your original array is modified when you modify the passed parameter. ... Thanks for the information, Scott. ... So I just assumed that the array that I was passing was using pass-by-value. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Passing arrays ByVal vs ByRef
    ... "Scott M." wrote in message ... If you pass a reference type (such as an Array), you get a copy of the reference, not the type and this explains why your original array is modified when you modify the passed parameter. ... So I just assumed that the array that I was passing was using pass-by-value. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Array conversion question
    ... > That's it Scott, ... >> Try the following (or something like it, untested code follows): ... >>> Christiaan ... ArrayList arr = new ArrayList; ...
    (microsoft.public.dotnet.languages.csharp)