- 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 34489 Articles for Programming
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
628 Views
The exception thrown when a null reference is passed to a method that does not accept it as a valid argument.Let us see an example.When we set a null parameter to int.Parse() method, then ArgumentNullException is thrown as shown below −Exampleusing System; class Demo { static void Main() { string val = null; int res = int.Parse(val); // error is thrown } }OutputThe following error is thrown when the above program is compiled since we have passed a null value.Unhandled Exception: System.ArgumentNullException: Value cannot be null.
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
350 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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
207 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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
103 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); } }
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
144 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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
788 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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
253 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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
156 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