
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# program to create a List with elements from an array
Set an array −
int[] val = new int[5]; // integer elements val[0] = 15; val[1] = 25; val[2] = 40; val[3] = 58; val[4] = 70;
Now set a list and add array in it −
List<int> myList = new List<int>(val);
The following is the code −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main() { int[] val = new int[5]; // integer elements val[0] = 15; val[1] = 25; val[2] = 40; val[3] = 58; val[4] = 70; List<int> myList = new List<int>(val); Console.WriteLine("Elements..."); foreach(int res in myList) { Console.WriteLine(res); } // count integer elements Console.WriteLine("Number of elements: "+myList.Count); } }
Output
Elements... 15 25 40 58 70 Number of elements: 5
- Related Articles
- Create linked list from a given array in C++ Program
- Program to create a list with n elements from 1 to n in Python
- Java Program to Get First and Last Elements from an Array List
- C# program to remove duplicate elements from a List
- C# Program to skip elements of an array from the end
- C program to reverse an array elements
- Java Program to create a new list with values from existing list with Function Mapper
- Java Program to create a new list with values from existing list with Lambda Expressions
- C# program to convert an array to an ordinary list with the same items
- C# Program to get the first three elements from a list
- PHP program to find missing elements from an array
- Swift Program to Remove Duplicate Elements From an Array
- Golang program to remove all elements from an array
- Golang Program To Remove Duplicate Elements From An Array
- Golang Program to Remove Repeated Elements From an Array

Advertisements