Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Int array or IList array. Join

3 views
Skip to first unread message

shapper

unread,
Dec 15, 2009, 7:26:35 PM12/15/09
to
Hello,

I need to hold a few ints on a variable and later add a few more but
in code line if possible.

I was trying and int array and concat or join but I wasn't able to
make it work:

Int32[] assetsIds = new Int32[] {1, 2};
List<Asset> assets = service.GetAssets(assetsIds.Contat(new Int32[]
{10, 12}));

I am not sure if I could, or should, use a List<Int32> instead ...

Thanks,
Miguel

Peter Duniho

unread,
Dec 15, 2009, 8:01:02 PM12/15/09
to
shapper wrote:
> Hello,
>
> I need to hold a few ints on a variable and later add a few more but
> in code line if possible.
>
> I was trying and int array and concat or join but I wasn't able to
> make it work:
>
> Int32[] assetsIds = new Int32[] {1, 2};
> List<Asset> assets = service.GetAssets(assetsIds.Contat(new Int32[]
> {10, 12}));

There is no "Contant()" method. Perhaps you meant "Concat()"?

You can use the Enumerable.Concat<TSource>() method, assuming the
GetAssets() method accepts IEnumerable.

> I am not sure if I could, or should, use a List<Int32> instead ...

Impossible to say without knowing what your code _really_ looks like
(you obviously have not posted the actual code).

Pete

Arne Vajhøj

unread,
Dec 15, 2009, 8:23:59 PM12/15/09
to

Both work.

Example:

using System;
using System.Collections.Generic;
using System.Linq;

namespace E
{
public class Program
{
public static void Main(string[] args)
{
List<int> a = new List<int> { 1, 2 };
List<int> b = a.Concat(new List<int> { 3, 4 }).ToList();
Console.WriteLine(string.Join(",", b.Select(v =>
v.ToString()).ToArray()));
int[] c = { 1, 2 };
int[] d = c.Concat(new int[] { 3, 4 }).ToArray();
Console.WriteLine(string.Join(",", b.Select(v =>
v.ToString()).ToArray()));
Console.ReadKey();
}
}
}

Arne

shapper

unread,
Dec 16, 2009, 9:02:54 AM12/16/09
to

I was doing it right with concat ... But I was missing the ToArray()
at the end.

Should I use int array or int list?

Basically I am sending the values to the method but inside the method
I will only read the values ...

Thank You,
Miguel

Peter Duniho

unread,
Dec 16, 2009, 12:59:11 PM12/16/09
to
shapper wrote:
> [...]

> Should I use int array or int list?

Should you "use int array or int list" where? In the call to your method?

> Basically I am sending the values to the method but inside the method
> I will only read the values ...

You should use the minimal type that the method will accept. Since you
didn't bother to tell us the method signature, we have no idea what type
you should pass to it. We can only tell you how to concatenate your arrays.

Pete

Arne Vajhøj

unread,
Dec 16, 2009, 8:13:09 PM12/16/09
to
On 16-12-2009 09:02, shapper wrote:
> I was doing it right with concat ... But I was missing the ToArray()
> at the end.
>
> Should I use int array or int list?

In most cases list would be better because you can easily change
the size.

Arne

0 new messages