Match Any String with 'p' at the End of It

Anjana
Updated on 23-Jun-2020 08:40:30

151 Views

To match any string with p at the end of it with JavaScript RegExp, use the p$ Quantifier.Example           JavaScript Regular Expression                        var myStr = "Welcome to our website! Welcome";          var reg = /me$/g;          var match = myStr.match(reg);                    document.write(match);          

C# LINQ LastOrDefault Method

Chandu yadav
Updated on 23-Jun-2020 08:40:21

2K+ Views

Use the LastorDefault() method to return the last element of a sequence or a default value if element isn’t there.The following is our empty list.List val = new List { };Now the following will not be able to display the last element since the list is empty. Therefore, the default would get display and error won’t be shown.val.AsQueryable().LastOrDefault();The following is the code.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo {    static void Main() {       List val = new List { };       double d = val.AsQueryable().LastOrDefault();       Console.WriteLine("Default Value = "+d); ... Read More

C# LINQ Zip Method

Samual Sam
Updated on 23-Jun-2020 08:39:48

1K+ Views

Merge sequences using predicate with Zip method.Here are our arrays to be merged.int[] intArray = { 10, 20, 30, 40 }; string[] stringArray = { "Jack", "Tim", "Henry", "Tom" };Now let’s use the Zip method to merge both the arrays.intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two)The following is our code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] intArray = { 10, 20, 30, 40 };       string[] stringArray = { "Jack", "Tim", "Henry", "Tom" };       var mergedSeq = intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two);       foreach (var ele in mergedSeq)       Console.WriteLine(ele);    } }Output10 Jack 20 Tim 30 Henry 40 Tom

Get Rank of a Three Dimensional Array in C#

Arjun Thakur
Updated on 23-Jun-2020 08:39:23

170 Views

To get the rank of a three-dimensional array, use the Rank property.Set a three-dimensional array.int[,,] arr = new int[3,4,5]Now get the rank.arr.RankLet us see the complete code.Exampleusing System; class Program {    static void Main() {       int[,,] arr = new int[3,4,5]       Console.WriteLine("Dimensions of Array : " + arr.Rank);    } }

Match Any String with 'p' at the Beginning

Smita Kapse
Updated on 23-Jun-2020 08:39:10

183 Views

To match any string with p at the beginning of it with JavaScript RegExp, use the ^p Quantifier −Example           JavaScript Regular Expression                        var myStr = "Welcome to our website. We Learners!";          var reg = /^We/g;          var match = myStr.match(reg);                    document.write(match);          

Get Bounds of a Hash Three-Dimensional Array

Ankith Reddy
Updated on 23-Jun-2020 08:37:49

507 Views

To get the bounds of a three-dimensional array, use the GetUpperBound() GetLowerBound() methods in C#.The parameter to be set under these methods is the dimensions i.e.Let’s say our array is −int[, , ] arr = new int[3, 4, 5];For a three-dimensional arrays, dimension 0.arr.GetUpperBound(0) arr.GetLowerBound(0)For a three-dimensional arrays, dimension 1.arr.GetUpperBound(1) arr.GetLowerBound(1)For a three-dimensional arrays, dimension 2.arr.GetUpperBound(2) arr.GetLowerBound(2)Let us see the entire example.Example Live Demousing System; class Program {    static void Main() {       int[, , ] arr = new int[3, 4, 5];       Console.WriteLine("Dimension 0 Upper Bound: {0}", arr.GetUpperBound(0).ToString());       Console.WriteLine("Dimension 0 Lower Bound: ... Read More

Get Width and Height of a Three-Dimensional Array

karthikeya Boyini
Updated on 23-Jun-2020 08:37:18

316 Views

Let’s say our three-dimensional array is −int[,,] arr = new int[3,4,5];To get the height and width i.e. the rows and columns.Array.GetLength(0) – for rows Array.GetLength(1) – for columnsExample Live Demousing System; class Program {    static void Main() {       int[,,] arr = new int[3,4,5];       Console.WriteLine(arr.GetLength(0));       Console.WriteLine(arr.GetLength(1));       Console.WriteLine(arr.GetLength(2));    } }Output3 4 5

LINQ SkipLast Method in C#

Samual Sam
Updated on 23-Jun-2020 08:36:50

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

C# Queryable SkipWhile Method

Arjun Thakur
Updated on 23-Jun-2020 08:36:30

156 Views

Bypass elements in an array and return the remaining elements using the SkipWhile() method.The following is our array −int[] marks = { 45, 88, 55, 90, 95, 85 };Now, let’s skip the elements greater than or equal to 60. The condition we have set using Lambda Expression.IEnumerable selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipWhile(s => s >= 60);Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] marks = { 45, 88, 55, 90, 95, 85 };       // skips elements above 60       IEnumerable selMarks = ... Read More

C# Enum TryParse Method

karthikeya Boyini
Updated on 23-Jun-2020 08:36:02

10K+ Views

The TryParse() method converts the string representation of one or more enumerated constants to an equivalent enumerated object.Firstly, set an enum.enum Vehicle { Bus = 2, Truck = 4, Car = 10 };Now, let us declare a string array and set some values.string[] VehicleList = { "2", "3", "4", "bus", "Truck", "CAR" };Now parse the values accordingly using Enum TryParse() method.Example Live Demousing System; public class Demo {    enum Vehicle { Bus = 2, Truck = 4, Car = 10 };    public static void Main() {       string[] VehicleList = { "2", "3", "4", "bus", "Truck", "CAR" ... Read More

Advertisements