i have:
int[] numbers = { 1, 2, 3};
string[] words = { "one", "two", "three" };
and need the output to be
1=one
2=two
3=three
thanks
i have:
int[] numbers = { 1, 2, 3};
string[] words = { "one", "two", "three" };
and need the output to be
1=one
2=two
3=three
thanks
I see that everybody is jumping to Linq or IEnumerable extensions when you don't grasp the basics. It will be like putting a child to college so I suggest you first learn using loops, like the for loop.
for (int i = 0; i < numbers.Length; i++) {
Console.WriteLine(String.Format("{0}-{1}", numbers[i], words[i]));
}
And Math class basics
int total = Math.Min(numbers.Length, word.Length);
for (int i = 0; i < total; i++) {
LINQ example:
var query = numbers.Select((n, i) => string.Format("{0}={1}", n, words[i]));
Edit:
In .NET 4.0 you can use Zip (as posted by mBotros) - there's even almost same example as what you're asking for on Zip MSDN doc page.
Zip extension is much better than this.Zip is .NET 4 child, I decided to leave this answer as well, .NET 3.5 is still quite popular :)Func<TSource, int, TResult> - but yes, when TSource is also int (as in our case) it's easy to confuse what goes where when you add index (which is int too) into the mix. Rule of thumb: whenever you can, use Zip instead :)