- 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 34489 Articles for Programming
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
Skip elements from the end and return the remaining elements using the SkipLast() method.The following is an array.int[] marks = { 45, 88, 50, 90, 95, 85 };Now, let us skip two elements from the end using SkipLast() and Lambda Expressions, but this is done after arranging the elements in descending order.IEnumerable selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipLast(2);Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] marks = { 45, 88, 50, 90, 95, 85 }; IEnumerable selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipLast(2); Console.WriteLine("Skipped ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
2K+ Views
The numeric ("N") format specifier converts a number to a string of the following form −"-d,ddd,ddd.ddd…"Above,"-" is a negative number symbol if required,"d" is a digit (0-9), "," indicates a group separator,"." is a decimal point symbolExample Live Demousing System; using System.Globalization; class Demo { static void Main() { double val1 = -5566.789; Console.WriteLine(val1.ToString("N", CultureInfo.InvariantCulture)); int val2 = 87987766; Console.WriteLine(val2.ToString("N3", CultureInfo.InvariantCulture)); } }Output-5,566.79 87,987,766.000
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
Skip elements and return the remaining elements using the Skip() method.The following is an array.int[] marks = { 80, 55, 79, 99 };Now, let us skip 2 elements using Lambda Expressions, but this is done after arranging the elements in descending order.IEnumerable selMarks = marks.AsQueryable().OrderByDescending(s => s).Skip(2);Exampleusing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] marks = { 80, 55, 79, 99 }; IEnumerable selMarks = marks.AsQueryable().OrderByDescending(s => s).Skip(2); Console.WriteLine("Skipped the result of 1st two students..."); foreach (int res in selMarks) { console.WriteLine(res); } } }
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
Let’s say we want to remove whitespace from the following string str1.string str1 = "Brad Pitt";Now, use Regex Replace to replace whitespace with empty. Here, we have used System.Text.RegularExpressions.string str2 = System.Text.RegularExpressions.Regex.Replace(str1, @"\s+", "");Let us see the complete example.Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo { class Program { static void Main(string[] args) { string str1 = "Brad Pitt"; Console.WriteLine(str1); string str2 = System.Text.RegularExpressions.Regex.Replace(str1, @"\s+", ""); Console.WriteLine(str2); } } }OutputBrad Pitt BradPitt
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
3K+ Views
The method returns a single specific element of a sequence. If the element is not present in the sequence, then the default value is returned.We have two string arrays here.string[] str1 = { "one" }; string[] str2 = { };First array is checked for a single element, whereas the second array is empty and checked using SingleorDefault.str2.AsQueryable().SingleOrDefault();The following is an example showing the usage of SingleorDefault() method.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] str1 = { "one" }; string[] str2 = { }; ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
283 Views
The Single() method returns the only element that satisfies a condition. If more than one such element is visible, then an error is thrown.The following is our string array.string[] str = { "jack", "tom", "henry", "time"};Now, use the Single() method to get each element. Then, we have used Lambda Expression to calculate an element whose length is greater than four.str.AsQueryable().Single(name => name.Length > 4);Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] str = { "jack", "tom", "henry", "time"}; // finding string whose length is ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
Get only a single element of a sequence using the Single() method.Let’s say we have a string array with only one element.string[] str = { "one" };Now, get the element.str.AsQueryable().Single();Here is our code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] str = { "one" }; string res = str.AsQueryable().Single(); Console.WriteLine(res); } }Outputone
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
240 Views
Use ReadAllLines() method to read all the lines one by one in a file.Let’s say we have a file “new.txt” with the following lines.One Two ThreeFirstly, set the path of the file to be read.String myPath = "new.txt";Now add it under a string array to fetch the lines on by one.String[] fLine = File.ReadAllLines(myPath);Let’s say you need to fetch the first line. For that.fLine[0]The following is the complete example that reads lines one by one in a file.Exampleusing System; using System.IO; public class Demo { public static void Main() { String myPath = "new.txt"; ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
302 Views
Declare a string array.string [] students = {"Jenifer", "Angelina", "Vera"};Add it to a LinkedList.string [] students = {"Jenifer", "Angelina", "Vera"};Now, use AddLast() method to add a node at the end.list.AddLast("Anne");Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { string [] students = {"Jenifer", "Angelina", "Vera"}; LinkedList list = new LinkedList(students); foreach (var stu in list) { Console.WriteLine(stu); } // add a node at the end Console.WriteLine("Node added at the last..."); list.AddLast("Anne"); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
85 Views
To check whether two sequences are equal or not, use the SequenceEqual() method.Firstly, set the sequences.Employee emp1 = new Employee { EmployeeRank = 4, EmpName = "Amit", EmpMarks = 90 }; Employee emp2 = new Employee { EmployeeRank = 5, EmpName = "Raman", EmpMarks = 95 }; List employee1 = new List { emp1, emp2 }; List employee2 = new List { emp1, emp2 };Now, find whether the sequences are equal or not.employee1.AsQueryable().SequenceEqual(employee2);Here is the example that shows the result.Exmaple Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { Employee ... Read More