C# help

Calling all nerds! Talk tech in this forum.

Moderator: Boni

User avatar
Boni
Administrator
Administrator
Posts: 5831
Joined: Sat May 19, 2007 12:17 pm
First name: Christopher
Age: 28
Gender:
PSN ID: BoniBoyBlue
Twitter: @boniboyblue
Location: Scotland
Contact:

Re: C# help

Post by Boni »

First code I learned was plain old C. Although at college is has nothing more than terminal based programs.
[donate][/donate]
User avatar
samueeL
Finnish Flash
Posts: 3755
Joined: Sun May 27, 2007 10:06 pm
Gender:
PSN ID: samueel41
Instrument 1: Guitar
Instrument 2: Piano
Instrument 3: Drums

Re: C# help

Post by samueeL »

Alright, thanks to my teacher's horrible instructions full of typos it was all wrong yet again. But I think I got it right this time, haha.

Code: Select all

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

namespace Lisatehtava
{
    public class ListatYhteen
    {
        /// <summary>
        /// Pääohjelma jossa luodaan ja alustetaan kaksi listaa
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            List<int> lista1 = new List<int> { 2, 4, 6, 8, 12, 13, 15 };
            List<int> lista2 = new List<int> { 2, 6, 1, 7, 8, 12, 15, 5, 1 };

            List<int> leikkausLista = Leikkaus(lista1, lista2);
            Console.WriteLine(string.Join(" ", leikkausLista));
        }


        /// <summary>
        /// Aliohjelma, jossa yhdistetään lista1:sen ja lista2:sen samat luvut listaksi 
        /// </summary>
        /// <param name="lista1">2,4,6,8,12,13,15</param>
        /// <param name="lista2">2,6,1,7,8,12,15,5,1</param>
        /// <returns>Leikkauksen: lista3</returns>
        public static List<int> Leikkaus(List<int> lista1, List<int> lista2)
        {
            List<int> lista3 = new List<int>();           
            foreach (int x in lista2)
            {
                if (lista1.Contains(x))
                {
                    lista3.Add(x);
                }
            }
            return lista3;
        }
    }
}
User avatar
Jake
Administrator
Administrator
Posts: 3196
Joined: Wed Jun 27, 2007 12:31 pm
First name: Jake :O
Age: 25
Gender:
Last.fm Username: Boneloner
Twitter: broughjc
Location: Portsmouth, England
Contact:

Re: C# help

Post by Jake »

haha, that looks good.
Image
<3 Sumfan


Donate to TNS:
[donate][/donate]
Post Reply