AddRange()
Written by: maffelu , 2009-04-17 07:22:07
namespace TestApp
{
public class Fplayers
{
public string Name;
public int Age;
public string Team;
public Fplayers(string name, int age, string team)
{
this.Name = name;
this.Age = age;
this.Team = team;
}
}
}
using System;
using System.Collections.Generic;
namespace TestApp
{
class Program
{
public static void Main(string[] args)
{
//Create the list
List<Fplayers> BestPlayers = new List<Fplayers>();
//Create three Fplayer objects
Fplayers player1 = new Fplayers("Zlatan Ibrahimovic", 27, "Inter");
Fplayers player2 = new Fplayers("Olof Mellberg", 31, "Juventus");
Fplayers player3 = new Fplayers("Marcus Rosenberg", 26, "Werder Bremen");
//Create an array and add the three Fplayer objects
Fplayers[] FplRange = new Fplayers[]{player1, player2, player3};
//Add the array to the list with the AddRange() method
BestPlayers.AddRange(FplRange);
//Output the result
Console.WriteLine("Great fooball players:\n\n");
BestPlayers.ForEach(delegate(Fplayers fpl)
{
Console.WriteLine("Name: {0}\nAge: {1}\nTeam: {2}\n", fpl.Name, fpl.Age, fpl.Team);
});
Console.Read();
}
}
}
There are no comments on this article.
If you have any question or just want to leave a message, just fill out the form below!
Your e-mail will not be visible in your post, it is for validation reasons only
Maffelu
Creator and admin of MorkaLork.com.
Started programming in HTML back when frames and tables was the way to design a page, moved on to Pascal/Delphi, PHP, javascript/jQuery, VB.NET/C#, Java and C++.
Currently studies .NET (in general) focusing on ASP.NET.