- 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 35164 Articles for Programming
278 Views
UShort represents a 16-bit unsigned integer.To implicitly convert of a 16-bit unsigned integer to a decimal, firstly set a ushort value.ushort val = 193;To convert ushort to decimal, assign the value.decimal dec; dec = val;Let us see an example.Exampleusing System; public class Demo { public static void Main() { ushort val = 2567; decimal dec; Console.WriteLine("Implicit conversion from 16-bit unsigned integer to Decimal"); dec = val; Console.WriteLine("Decimal = "+dec); } }
293 Views
Use Orderby descending in C# to sort elements in descending order.The following is our list −IList emp = new List() { new Employee() { EmployeeRank = 3, EmpName = "Tom", EmpMarks = 90 } , new Employee() { EmployeeRank = 4, EmpName = "Katie", EmpMarks = 95 } };Now to sort the list according to Student name, use Orderby. The default is ascending, therefore for descending order, use descending.var res = from str in emp orderby str.EmpName descending select str;Here is the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { ... Read More
826 Views
To represent Int32 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.Int32 represents a 32-bit signed integer.Firstly, set an Int32 variable.int val = 99;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() { int val = 99; Console.WriteLine("Integer: "+val); Console.Write("Octal String: "+Convert.ToString(val, 8)); } }OutputInteger: 99 Octal String: 143
696 Views
The following is our list with elements −IList emp = new List() { new Employee() { EmployeeRank = 4, EmpName = "Amit", EmpMarks = 90 } , new Employee() { EmployeeRank = 05, EmpName = "Raman", EmpMarks = 95 } };Now use orderby and descending to sort elements in descending order.var res = from str in emp orderby str.EmpName descending select str;Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { IList emp = new List() { new Employee() { EmployeeRank = 4, EmpName ... Read More
79 Views
Get the minimum value from a sequence using the Min() method in C#.The following is our list.List list = new List { 1, 2, 3, 4, 5, 6 };Now, use Queryable Min() method to get minimum element.list.AsQueryable().Min();Exampleusing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List list = new List { 1, 2, 3, 4, 5, 6 }; foreach(long ele in list) { Console.WriteLine(ele); } // getting lowest element long min_num = list.AsQueryable().Min(); Console.WriteLine("Smallest number = {0}", mix_num); } }
124 Views
Get the maximum value from a sequence using the Max() method.Let’s say the following is our list.List list = new List { 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000 };Use the Max() method to get the largest element.list.AsQueryable().Max();Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List list = new List { 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000 }; foreach(long ele in list) Console.WriteLine(ele); // getting largest element long max_num = list.AsQueryable().Max(); Console.WriteLine("Largest number = {0}", max_num); } }Output200 400 600 800 1000 1200 1400 1600 1800 2000 Largest number = 2000
3K+ Views
AsQueryable() method is used to get an IQueryable reference.Let us see an example to find sum of integer values.Firstly, set an integer array.var arr = new int[] { 100, 200, 300, 400 };Now to find the sum, use the Queryable Sum() and AsQueryable() method.Queryable.Sum(arr.AsQueryable());The following is the complete code.Example Live Demousing System; using System.Linq; class Demo { static void Main() { var arr = new int[] { 100, 200, 300, 400 }; int res = Queryable.Sum(arr.AsQueryable()); Console.WriteLine("Sum: "+res); } }OutputSum: 1000
1K+ Views
Convert the specified value to its equivalent string using the ToString() method.Initialize a bool value.bool boolVal = false;Now, to convert it to a string, use the ToString() method.Convert.ToString(boolVal)The following is the complete example.Example Live Demousing System; public class Demo { public static void Main() { bool boolVal = false; Console.WriteLine(Convert.ToString(boolVal)); } }OutputFalse
1K+ Views
The method matches instances of a pattern and is used to extract value based on a pattern.Let us see hoe to check for a valid URL.For that, pass the regex expression in the Matches method.MatchCollection mc = Regex.Matches(text, expr);Above, the expr is our expression that we have set to check for valid URL."^(http|http(s)?://)?([\w-]+\.)+[\w-]+[.com|.in|.org]+(\[\?%&=]*)?”The text we have set to check is a URL i.e.https://demo.comLet us see the complete code.Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo { class Program { private static void showMatch(string text, string expr) { MatchCollection mc = Regex.Matches(text, expr); ... Read More
18K+ Views
Use the FirstorDefault() method to return the first element of a sequence or a default value if element isn’t there.The following is our empty list −List val = new List { };Now, we cannot display the first element, since it is an empty collection. For that, use the FirstorDefault() method to display the default value.val.AsQueryable().FirstOrDefault();The following is the complete example.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List val = new List { }; double d = val.AsQueryable().FirstOrDefault(); Console.WriteLine("Default Value = "+d); ... Read More
To Continue Learning Please Login
Login with Google