Int array or IList array. Join

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

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
 
shapper said:
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()"?

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

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

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

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
 
shapper said:
[...]
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
 
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 ...

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();
}
}

}

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