Answer the question
In order to leave comments, you need to log in
C#. How can two array declarations be combined?
We need a method to combine them, but how? In one case i+2, and in the other i+1
var days = new string[30];
for (var i = 0; i < days.Length; i++)
days[i] = Convert.ToString(i + 2);
var months = new string[12];
for (var i = 0; i < months.Length; i++)
months[i] = Convert.ToString(i + 1);
Answer the question
In order to leave comments, you need to log in
It's not clear how to combine them.
If you just need to join these two arrays, then:
public string[] UnionArrays(string[] days, string[] months) {
var daysAndMonths = new string[days.Length+months.Length];
for (var i = 0; i < days.Length; i++)
daysAndMonths[i] = days[i];
for (var i = 0; i < months.Length; i++)
daysAndMonths[days.Length+i] = months[i];
return daysAndMonths;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question