- 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
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
256 Views
The SequenceEqual method is used to test collections for equality.Let us set three string arrays −string[] arr1 = { "This", "is", "it" }; string[] arr2 = { "My", "work", "report" }; string[] arr3 = { "This", "is", "it" };Now, compare the first array with the second using the SequenceEqual() method −arr1.SequenceEqual(arr2);The following is an example −Example Live Demousing System; using System.Linq; class Program { static void Main() { string[] arr1 = { "This", "is", "it" }; string[] arr2 = { "My", "work", "report" }; string[] arr3 = { "This", "is", "it" }; bool res1 = arr1.SequenceEqual(arr2); Console.WriteLine(res1); bool res2 = arr1.SequenceEqual(arr3); Console.WriteLine(res2); } }OutputFalse True
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
358 Views
The Any() extension method is part of the System.Linq namepspace. Using this method, you can check whether any of the elements matches a certain condition or not.Firstly, set an array with elements −int[] arr = { 6, 7, 15, 40, 55 };The following is an example. It checks whether any of the element in the array is greater than and equal to 20 or not −arr.Any(element => element >= 20);Here is the complete code −Example Live Demousing System; using System.Linq; class Program { static void Main() { int[] arr = { 6, 7, 15, 40, 55 }; bool res = arr.Any(element => element >= 20); Console.WriteLine(res); } }OutputTrue
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
8K+ Views
Use the Take() method to get the first individual number of elements in C#.Firstly, set a list and add elements −List myList = new List(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four"); myList.Add("Five"); myList.Add("Six");Now, use the Take() method to get the elements from the list. Add the number of the elements you want as an argument −myList.Take(3)Here is the code −Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { List myList = new List(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four"); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
467 Views
Declare an array −int[] arr = { 10, 90, 20, 19, 99, 57 };Now to get the largest element from an array, use Max() method with lambda expressions −arr.Max());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { int[] arr = { 10, 90, 20, 19, 99, 57 }; Console.WriteLine(arr.Max(element => Math.Abs(element))); } }Output99
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
284 Views
SkipWhile skips an element when a condition is matched.For example, use the following if you want to skip all even elements −ele => ele %2 == 0The following is an example wherein all the even elements are skipped and only the odd elements are displayed −Example Live Demousing System.IO; using System; using System.Linq; public class Demo { public static void Main() { int[] arr = { 20, 35, 55 }; Console.WriteLine("Initial array..."); foreach (int value in arr) { Console.WriteLine(value); } // ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
If you want to skip a number of elements in an array, then use the Skip() method in C#.Let’s say the following is our array −int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };Now to skip first four elements −var ele = arr.Skip(4);Let us see the complete example −Example Live Demousing System.IO; using System; using System.Linq; public class Demo { public static void Main() { int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 }; Console.WriteLine("Initial Array..."); foreach (var res in arr) ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
3K+ Views
ElementAt() is a System.Linq method in C# that is used to get and display element at a particular index.The following is our string array −string[] arr = { "One", "Two", "Three", "Four", "Five" };Now to get an element at index 0, use the ElementAt() method −arr.ElementAt(0);The following is the complete code −Example Live Demousing System.IO; using System; using System.Linq; public class Demo { public static void Main() { string[] arr = { "One", "Two", "Three", "Four", "Five" }; // displaying element at index 0 string res = arr.ElementAt(0); Console.WriteLine(res); } }OutputOne
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
268 Views
To specify number types, use suffixes in C#. Literal number suffixes are numeric suffixes.For example, for long type −// long suffix long val1 = 29345L;For double type −// double suffix double val2 = 297.325D; Console.WriteLine(val2);Let us see more examples −Example Live Demousing System.IO; using System; public class Program { public static void Main() { // long suffix long val1 = 29345L; Console.WriteLine(val1); // decimal suffix decimal val5 = 3245.5678M; Console.WriteLine(val5); // double suffix double val2 = 297.325D; Console.WriteLine(val2); // float suffix float val3 = 250.35F; Console.WriteLine(val3); // unsigned suffix uint val4 = 3456U; Console.WriteLine(val4); } }Output29345 3245.5678 297.325 250.35 3456
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
100 Views
Set lowercase suffixes for literals such as u, l, ul, f, etc.// l for long long a = 29876l;It can be used on literal numbers as well. It tells the compiler that the literal is of a specific type.The following is an example −Example Live Demousing System.IO; using System; public class Program { public static void Main() { long a = 29876l; float b = 95.10f; Console.WriteLine(a); Console.WriteLine(b); } }On running the above example, you will get the following output. With that, you will also get a ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
To get the creation time of a file in C#, use the CreationTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("new.txt"); DateTime dt = file.CreationTime;Let us see the complete code −Example Live Demousing System.IO; using System; public class Program { public static void Main() { using (StreamWriter sw = new StreamWriter("qa.txt")) { sw.WriteLine("Questions and Answers!"); } FileInfo file = new FileInfo("qa.txt"); // file creation time DateTime dt = file.CreationTime; Console.WriteLine(dt); } }Output9/5/2018 5:20:03 AM