
- 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 find the cube of elements in a list
Use Select method and Lambda Expression to calculate the cube of elements.
The following is our list.
List<int> list = new List<int> { 2, 4, 5, 7 };
Now, use the Select() method and calculate the cube.
list.AsQueryable().Select(c => c * c * c);
The following is the entire example.
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { List<int> list = new List<int> { 2, 4, 5, 7 }; Console.WriteLine("Elements..."); // initial list javascript:void(0) foreach (int n in list) Console.WriteLine(n); // cube of each element IEnumerable<int> res = list.AsQueryable().Select(c => c * c * c); Console.WriteLine("Cube of each element..."); foreach (int n in res) Console.WriteLine(n); } }
Output
Elements... 2 4 5 7 Cube of each element... 8 64 125 343
- Related Articles
- Python Program to find the cube of each list element
- Python program to find sum of elements in list
- Program to find duplicate item from a list of elements in Python
- Program to find the kth missing number from a list of elements in Python
- Program to find highest common factor of a list of elements in Python
- Find sum of elements in list in Python program
- Python program to find Tuples with positive elements in a List of tuples
- Program to find largest sum of non-adjacent elements of a list in Python
- Python Program to Find Number of Occurrences of All Elements in a Linked List
- Program to find sum of odd elements from list in Python
- Program to find a list of product of all elements except the current index in Python
- Program to find sum of non-adjacent elements in a circular list in python
- Java program to find the cube root of a given number
- Python program to find N largest elements from a list
- Java program to find a cube of a given number

Advertisements