- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34494 Articles for Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
139 Views
Perform Union on two sequences using the Queryable Union method.The following are our arrays.int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 }; int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 };Now, get the Union of the arrays using the Union method.arr1.AsQueryable().Union(arr2);Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 }; int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 }; IEnumerable res = arr1.AsQueryable().Union(arr2); foreach (int a in res) Console.WriteLine("{0} ", a); } }Output29 40 15 55 70 30 90 36 18 75
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
787 Views
Add a node before a given node in C# using the AddBefore() method.Our LinkedList with string nodes.string [] students = {"Henry", "David", "Tom"}; LinkedList list = new LinkedList(students);Now, let’s add node at the end.// adding a node at the end var newNode = list.AddLast("Brad");Use AddBefore() method to add a node before the node added above.list.AddBefore(newNode, "Emma");Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { string [] students = {"Henry", "David", "Tom"}; LinkedList list = new LinkedList(students); foreach (var stu in list) { Console.WriteLine(stu); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
247 Views
Orders elements in a sequence using ThenBy() method.We have the following string array.string[] str = { "AAA", "AAAA", "A", "AAAAA", "AAAAAAAAA" };Now, use Lambda Expressions and set a condition inside the ThenBy() method to sort the strings according to the number of characters they have.IEnumerable res = str.AsQueryable() .OrderBy(alp => alp.Length).ThenBy(alp => alp);Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] str = { "AAA", "AAAA", "A", "AAAAA", "AAAAAAAAA" }; IEnumerable res = str.AsQueryable() .OrderBy(alp => alp.Length).ThenBy(alp => alp); foreach (string arr ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
156 Views
To orders elements in a sequence in descending order, use ThenBy() and OrderByDescending.This is our string array.string[] myStr = { "Keyboard", "Laptop", "Mouse", "Monitor" };Now, use OrderByDescending to order element in Descending order. Inside that calculate the length of each string and use Lambda Expressions as well.IEnumerable res = myStr.AsQueryable().OrderByDescending(ch => ch.Length).ThenBy(ch => ch);The following is the example discussed above.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] myStr = { "Keyboard", "Laptop", "Mouse", "Monitor" }; IEnumerable res = myStr.AsQueryable().OrderByDescending(ch => ch.Length).ThenBy(ch => ch); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
82 Views
Use ThenBy() method to order array elements. Let’s say we have the following string array.string[] str = { "Sandler", "Jack", "Tom", "Matt", "Henry", "Johnny" };Now, use Lambda Expressions and set a condition inside the ThenBy() method to sort the strings according to the number of characters they have.IEnumerable res = str.AsQueryable().OrderBy(alp => alp.Length).ThenBy(alp => alp);Here is the entire example to order array elements using ThenBy() method.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] str = { "Sandler", "Jack", "Tom", "Matt", "Henry", "Johnny" }; IEnumerable ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
141 Views
To reprsent Int64 as a Octal string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 8 for Octal.Int64 represents a 64-bit signed integer.Firstly, set an Int64 variable.long val = 986766;Now, convert it to octal string by including 8 as the second parameter.Convert.ToString(val, 8)Example Live Demousing System; class Demo { static void Main() { long val = 986766; Console.WriteLine("Long: "+val); Console.Write("Octal String: "+Convert.ToString(val, 8)); } }OutputLong: 986766 Octal String: 3607216
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
498 Views
Get elements as long as the condition is true in a sequence using the TakeWhile() method.The following is our list with strings.IList str = new List(){ "Car", "Bus", "Truck", "Airplane"};Now, let’s say we need the strings whose length is less than 4. For that, use Lambda Expressions and add it as a condition in the TakeWhile() method.str.TakeWhile(a => a.Length < 4);Here is the example that displays elements until the condition is trie.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { IList str = new List(){ "Car", "Bus", "Truck", "Airplane"}; ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
1K+ Views
Get specified number of elements from the end using the TakeLast() method.The following is our array.int[] pages = { 492, 290, 129, 602, 152 };Now, use OrderBy to order the elements in ascending order. Then use the TakeLast() method to get specified number of elements from the end.marks.AsQueryable().OrderByDescending(s => s).Take(5);Let us see the complete example.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { // pages of books int[] pages = { 492, 290, 129, 602, 152 }; // get pages of last two ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
Get specified number of elements from the beginning using the Take() method.The following is our array.int[] marks = { 35, 72, 50, 90, 95, 85, 52, 67 };Now, use OrderByDescending to order the elements in Descending order. Then use the Take() method to get the elements.marks.AsQueryable().OrderByDescending(s => s).Take(5);Let us see the complete example.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] marks = { 35, 72, 50, 90, 95, 85, 52, 67 }; // top 5 student marks IEnumerable selMarks = marks.AsQueryable().OrderByDescending(s => s).Take(5); foreach (int res in selMarks) { Console.WriteLine(res); } } }Output95 90 85 72 67
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
467 Views
Firstly, set a sequence.List myList = new List { 1, 2, 3, 4 ,5};Now find the sum using the Queryable Sum() method.myList.AsQueryable().Sum();Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { List myList = new List { 1, 2, 3, 4 ,5}; Console.WriteLine("Sum of elements in a list..."); foreach (int res in myList) { Console.WriteLine(res); } int sum = myList.AsQueryable().Sum(); Console.WriteLine("Sum = {0}", sum); } }OutputSum of elements in a list... 1 2 3 4 5 Sum = 15