- 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
587 Views
The f is a lowercase suffix set while declaring a float. It tells the compiler that the literal is of a specific type.Example Live Demousing System.IO; using System; public class Program { public static void Main() { float val = 30.22f; Console.WriteLine(val); } }Output30.22Above, we have set the float using f suffix.IEnumerable res = val1.AsQueryable().Intersect(val2);
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
130 Views
Use the Linq LongCount method to get the count of elements.The following is our string array −string[] emp = { "Jack", "Mark"};Now, use the LongCount() method.emp.AsQueryable().LongCount();Here is the complete code.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { string[] emp = { "Jack", "Mark"}; long res = emp.AsQueryable().LongCount(); Console.WriteLine("{0} employees in the Department", res); } }Output2 employees in the Department
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
545 Views
To get the distinct elements, use the Distinct() method.The following is our list with duplicate elements.List points = new List { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 };Now to get the distinct elements −points.AsQueryable().Distinct();Let us see the entire example −Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Demo { static void Main() { List points = new List { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 }; // distict elements from the list IEnumerable res = points.AsQueryable().Distinct(); foreach (int a in res) { Console.WriteLine(a); } } }Output5 10 20 30 40 50 60 70
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
321 Views
Here is the string.string str = "ppqqrr";Now, use Hashset to map the string to char. This will remove the duplicate characters from a string.var res = new HashSet(str);Let us see the complete example −Example Live Demousing System; using System.Linq; using System.Collections.Generic; namespace Demo { class Program { static void Main(string[] args) { string str = "ppqqrr"; Console.WriteLine("Initial String: "+str); var res = new HashSet(str); Console.Write("New String after removing duplicates:"); foreach (char c in res){ Console.Write(c); } } } }OutputInitial String: ppqqrr New String after removing duplicates:pqr
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
The All Method checks for all the values in a collection and returns a Boolean. Even if one of the element do not satisfy the set condition, the All() method returns False.Let us see an example −int[] arr = {10, 15, 20};Now, using All() method, we will check whether each element in the above array is greater than 5 or not.arr.AsQueryable().All(val => val > 5);Example Live Demousing System; using System.Linq; class Demo { static void Main() { int[] arr = {10, 15, 20}; // checking if all the array elements are greater than 5 bool res = arr.AsQueryable().All(val => val > 5); Console.WriteLine(res); } }OutputTrue
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
1K+ Views
To represent Int64 as a Binary string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 2 for Binary.Int64 represents a 64-bit signed integer.Firstly, set an Int64 variable.long val = 753458;Now, convert it to binary string by including 2 as the second parameter.Convert.ToString(val, 2)Example Live Demousing System; class Demo { static void Main() { long val = 753458; Console.WriteLine("Long: "+val); Console.Write("Binary String: "+Convert.ToString(val, 2)); } }OutputLong: 753458 Binary String: 10110111111100110010
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
458 Views
The Aggregate() method applies an accumulator function over a sequence.The following is our array −string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"};Now use the Aggregate() method. We have set the ssed value as “DemoFive” for comparison.string res = arr.AsQueryable().Aggregate("DemoFive", (longest, next) => next.Length > longest.Length ? next : longest, str => str.ToLower());Here, the resultant string should have more number of characters than the initial seed value i.e. “DemoFive”.Example Live Demousing System; using System.Linq; class Demo { static void Main() { string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"}; string res = arr.AsQueryable().Aggregate("DemoFive", (longest, next) ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
Enumerable.Repeat method is part of System.Linq namespace.It returns a collection with repeated elements in C#.Firstly, set which element you want to repeat and how many times.As an example, let us see how to repeat number 10, five times −Enumerable.Repeat(10, 5);The following is the complete example −Example Live Demousing System; using System.Linq; class Demo { static void Main() { var val = Enumerable.Repeat(10, 5); foreach (int res in val) { Console.WriteLine(res); } } }Output10 10 10 10 10
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
175 Views
Use the Convert.ToUInt16 method to convert a specified value to a 16-bit unsigned integer.Here is our string −string str = "1129";Now let us convert it to 16-bit unsigned integer.ushort res; res = Convert.ToUInt16(str);The following is the complete example −Example Live Demousing System; public class Demo { public static void Main() { string str = "1307"; ushort res; res = Convert.ToUInt16(str); Console.WriteLine("Converted string '{0}' to {1}", str, res); } }OutputConverted string '1307' to 1307
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
623 Views
Convert a specified value to a 16-bit signed integer using the Convert.ToInt16 method in C#.We have a double variable with a value initialized to it.double doubleNum = 3.456;Now, let us convert it to Int16 i.e. short.short shortNum; shortNum = Convert.ToInt16(doubleNum);Here is the complete example −Example Live Demousing System; public class Demo { public static void Main() { double doubleNum = 3.456; short shortNum; shortNum = Convert.ToInt16(doubleNum); Console.WriteLine("Converted {0} to {1}", doubleNum, shortNum); } }OutputConverted 3.456 to 3