Alright, I know I suck but bare with me and plz give me quick answer so I can chill on my vacation... :D
In the main program I need to make two arrays and put some numbers in them like I did. Alright so the problem is with subprogram: it's supposed to return array with those numbers I used in the main program arrays. (in this case 1, 2, 3 & 5) How do I do it?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
public class TaulukotYhteen
{
/// <summary>
/// Pääohjelma, jossa alustetaan kaksi taulukkoa kokonaisluvuilla
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
int[] t1, t2;
t1 = new int[2] { 1, 2 };
t2 = new int[2] { 3, 5 };
int[] t3 = Leikkaus(t1, t2);
Console.WriteLine(t3);
Console.ReadKey();
}
/// <summary>
/// Aliohjelma joka yhdistää taulukoiden t1 ja t2 alkiot samaan taulukkoon t3 ja palauttaa sen
/// </summary>
/// <param name="t1"></param>
/// <param name="t2"></param>
/// <returns></returns>
public static int[] Leikkaus(int[] t1, int[] t2)
{
var list = new List<int>();
list.AddRange(t1);
list.AddRange(t2);
int[] t3 = list.ToArray();
return t3;
}
}
}
This gives me blank :e
Last edited by samueeL on Tue Dec 20, 2011 7:29 pm, edited 1 time in total.
You're not late guys, my answer wasn't correct. I was supposed to "cut" the lists instead of copying and use loop in the subprogram (for example for/while etc.) Can you guys help out? :e Main program can basically only have those arrays or you can use lists too.
Jake wrote:You just need to use a loop? to do anything you want?
And you can't add a 3rd array?
I need to use loop to add the numbers of those two main program arrays together. I gotta do it with loop.
Main program can only have 2 arrays and the subprogram returns one array that has the numbers from two arrays of the main program.
So Main program = 2 arrays/lists
Subprogram = loop + array/list
using System;
public class ListsTogether
{
/// <summary>
/// In the main program we initialize two lists and add numbers into them
/// </summary>
static void Main(string[] args)
{
List<int> lista1 = new List<int>();
list1.Add(2);
list1.Add(4);
list1.Add(6);
list1.Add(8);
List<int> list2 = new List<int>();
list2.Add(1);
list2.Add(3);
list2.Add(5);
list2.Add(7);
Cut(lista1, lista2); ?????????
}
/// <summary>
/// Subprogram that adds list1 and list2 together with a loop and puts them into list3 and returns that
/// </summary>
public static List<int> Cut(List<int> list1, List<int> list2)
{
//LOOP(S) THAT ADDS LIST1 AND LIST2 INTO LIST3 HERE
return list3;
}
}
}
for (int i = 0; i < list1.Count; i++)
{
list3.add(list1[i]);
}
for (int i = 0; i < list2.Count; i++)
{
list3.add(list2[i]);
}
Ahh thank you, it does indeed seem to work! So this should be okay for my teacher... :D If this passes, I'll blow you!
wtf are you studying and how did you manage to get this far avoiding loops? haha :P
Studying pedagogics and computer stuff at university and believe me, avoiding them has been hard but I've managed :D So basically IT teacher... So I don't REALLY need to know this stuff, I just need to pass courses! And loops are pain in the ass.
for (int i = 0; i < list1.Count; i++)
{
list3.add(list1[i]);
}
for (int i = 0; i < list2.Count; i++)
{
list3.add(list2[i]);
}
Ahh thank you, it does indeed seem to work! So this should be okay for my teacher... :D If this passes, I'll blow you!
wtf are you studying and how did you manage to get this far avoiding loops? haha :P
Studying pedagogics and computer stuff at university and believe me, avoiding them has been hard but I've managed :D So basically IT teacher... So I don't REALLY need to know this stuff, I just need to pass courses! And loops are pain in the ass.
Learning something like VB first would have helped :P
for (int i = 0; i < list1.Count; i++)
{
list3.add(list1[i]);
}
for (int i = 0; i < list2.Count; i++)
{
list3.add(list2[i]);
}
Ahh thank you, it does indeed seem to work! So this should be okay for my teacher... :D If this passes, I'll blow you!
wtf are you studying and how did you manage to get this far avoiding loops? haha :P
Studying pedagogics and computer stuff at university and believe me, avoiding them has been hard but I've managed :D So basically IT teacher... So I don't REALLY need to know this stuff, I just need to pass courses! And loops are pain in the ass.
Learning something like VB first would have helped :P
Indeed... But slowly getting hang of things.
Is there a command that deletes those list1 and list2 after using them in loop?
for (int i = 0; i < list1.Count; i++)
{
list3.add(list1[i]);
}
for (int i = 0; i < list2.Count; i++)
{
list3.add(list2[i]);
}
Ahh thank you, it does indeed seem to work! So this should be okay for my teacher... :D If this passes, I'll blow you!
wtf are you studying and how did you manage to get this far avoiding loops? haha :P
Studying pedagogics and computer stuff at university and believe me, avoiding them has been hard but I've managed :D So basically IT teacher... So I don't REALLY need to know this stuff, I just need to pass courses! And loops are pain in the ass.
Learning something like VB first would have helped :P
Indeed... But slowly getting hang of things.
Is there a command that deletes those list1 and list2 after using them in loop?