

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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
- Create linked list from a given array in C++ Program
- PHP program to find missing elements from an array
- 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
- Java Program to Remove Duplicates from an Array List
- JavaScript construct an array with elements repeating from a string
- How to create comma separated list from an array in PHP?
- C# program to remove duplicate elements from a List
- Python program to remove Duplicates elements from a List?
- Java program to remove duplicates elements from a List
- Python Program to Remove Palindromic Elements from a List
- Create an object array from elements of LinkedList in Java
- Python Program to extracts elements from a list with digits in increasing order
Advertisements