Generics C#

Fill a List with an Array

This C# program demonstrates how to fill a list with an array of elements.

Program.cs

using System;
using System.Collections.Generic;


namespace XoaX {

    class Program {
        static void Main(string[] args) {
            string[] saGiftsOfTheHolySpirit = new string[] {
               "Wisdom",
               "Understanding",
               "Counsel",
               "Fortitude",
               "Knowledge",
               "Piety",
               "Fear of the Lord"
           };

            List<string> qGiftsOfTheHolySpirit = new List<string>(saGiftsOfTheHolySpirit);

            Console.WriteLine("Gifts of the Holy Spirit:");
            Console.WriteLine("-------------------------");
            foreach (string sGift in qGiftsOfTheHolySpirit) {
                Console.WriteLine(sGift);
            }
            Console.WriteLine("");
        }
    }

}


 

Output

Gifts of the Holy Spirit:
-------------------------
Wisdom
Understanding
Counsel
Fortitude
Knowledge
Piety
Fear of the Lord

Press any key to continue . . .
 
 

© 2007–2024 XoaX.net LLC. All rights reserved.