Chash Average Method

George John
Updated on 23-Jun-2020 08:43:44

23K+ Views

To find the average of integers in C#, use the Queryable Average() method.Let’s say the following is our integer array.var arr = new int[] { 10, 17, 25, 30, 40, 55, 60, 70 };Now, use the Average() method to get the average of the elements.double avg = Queryable.Average(arr.AsQueryable());Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       var arr = new int[] { 10, 17, 25, 30, 40, 55, 60, 70 };       double avg = Queryable.Average(arr.AsQueryable());       Console.WriteLine("Average = "+avg);    } }OutputAverage = 38.375

C# Chash Cast Method

Samual Sam
Updated on 23-Jun-2020 08:43:19

2K+ Views

To cast elements, use the Cast() method.The following is our list.List myList = new List { "Mac", "Windows", "Linux", "Solaris" };Now, cast and use the Cast() method with substring() method to display the first two letters of every string in the list.IEnumerable res = myList.AsQueryable().Cast().Select(str => str.Substring(0, 2));Let us see the complete example.Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Demo {    static void Main() {       List list = new List { "keyboard", "mouse", "joystick", "monitor" };       // getting first 2 letters from every string       IEnumerable res = list.AsQueryable().Cast().Select(str => ... Read More

Force a Number to Display in Exponential Notation

Sravani S
Updated on 23-Jun-2020 08:43:16

973 Views

Use the toExponential() method to force a number to display in exponential notation, even if the number is in the range in which JavaScript normally uses standard notation.The following is the parameter −fractionDigits - An integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number.ExampleYou can try to run the following code to force a number to display in exponential function −           Javascript Method toExponential()                        var num=77.1234;          var ... Read More

Return String Value of Current Number

Manikanth Mani
Updated on 23-Jun-2020 08:42:43

231 Views

The toLocaleString() method returns a string value version of the current number in a format that may vary according to a browser's local settings.ExampleYou can try to run the following code to return a string value version −           JavaScript toLocaleString() Method                        var num = new Number(150.1234);          document.write( num.toLocaleString());          

Represent int64 as an Octal String in C#

Arjun Thakur
Updated on 23-Jun-2020 08:42:28

257 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

C# LINQ ThenBy Method

Ankith Reddy
Updated on 23-Jun-2020 08:42:08

351 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

C# Program to Order Array Elements in Descending Order

Samual Sam
Updated on 23-Jun-2020 08:41:43

264 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

Return Unicode Value of Character

Alankritha Ammu
Updated on 23-Jun-2020 08:41:29

376 Views

The charCodeAt() method returns a number indicating the Unicode value of the character at the given index. Unicode code points range from 0 to 1, 114, 111. The first 128 Unicode code points are a direct match of the ASCII character encoding.The following parameter is supported by charCodeAt(index) −index − An integer between 0 and 1 less than the length of the string; if unspecified, defaults to 0.ExampleYou can try to run the following code to return a number indicating the Unicode value of the character −           JavaScript String charCodeAt() Method           ... Read More

LinkedList addBefore Method in C#

George John
Updated on 23-Jun-2020 08:41:18

1K+ 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

C# Queryable Union Method

karthikeya Boyini
Updated on 23-Jun-2020 08:40:48

242 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

Advertisements