- 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
114 Views
The increment operator is ++ operator. If used as prefix on a variable, the value of variable gets incremented by 1. After that the value is returned unlike Postfix operator. It is called Prefix increment operator. In the same way the decrement operator works but it decrements by 1.For example, ++a;The following is an example demonstrating Prefix increment operator −Example Live Demousing System; class Program { static void Main() { int a, b; a = 10; Console.WriteLine(++a); b = a; Console.WriteLine(a); Console.WriteLine(b); } }Output11 11 11
227 Views
It handles errors generated from referencing a null object. The Null reference exception occurs when you are looking to access member fields or function types that points to null.Let’s say we have the following null string −string str = null;Now you try to get the length of the null string, then it would cause an exception −If(str.Length == null) {}Above the exception will be thrown. Now let us seen how to prevent the null pointer exception to be thrown −Example Live Demousing System; class Program { static void Main() { int[] arr = new int[5] {1, ... Read More
205 Views
The #undef directive allows you to undefine a symbol. The following is the syntax −#undef SYMBOLFor example,#undef OneIt evaluates to false when used along with #if directive. Let us see an example −Example Live Demo#define One #undef Two using System; namespace Demo { class Program { static void Main(string[] args) { #if (One && TWO) Console.WriteLine("Both are defined"); #elif (ONE && !TWO) Console.WriteLine("ONE is defined and TWO is undefined"); #elif (!ONE && TWO) Console.WriteLine("ONE is defined and TWO is undefined"); #else Console.WriteLine("Both are undefined"); #endif } } }OutputBoth are undefined
309 Views
To find the number of dimensions of an array, use the Array Rank property. This is how you can define it −arr.RankHere, arr is our array −int[,] arr = new int[3,4];If you want to get the rows and columns it has, then uses the GetLength property −arr.GetLength(0); arr.GetLength(1);The following is the complete code −Example Live Demousing System; class Program { static void Main() { int[,] arr = new int[3,4]; Console.WriteLine(arr.GetLength(0)); Console.WriteLine(arr.GetLength(1)); // Length Console.WriteLine(arr.Length); Console.WriteLine("Dimensions of Array : " + arr.Rank); } }Output3 4 12 Dimensions of Array : 2
255 Views
A Jagged array is an array of arrays. You can declare a jagged array named points of type int as −int [][] points;Let us now see how to initialize it −int[][] points = new int[][]{new int[]{10, 5}, new int[]{30, 40}, new int[]{70, 80}, new int[]{ 60, 70 }};Access the jagged array element as −points[i][j]);The following is the complete example showing how to work with jagged arrays in C# −Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { int[][] pages = new int[][]{new int[]{400, 345}, new ... Read More
389 Views
To declare a tuple the following is the format wherein we have a tuple with int and string items −Tuple tuple = new Tuple(20, "Tom");Now, check for first item in the tuple, which is an integer −if (tuple.Item1 == 99) { Console.WriteLine(tuple.Item1); }Now check for second item in the tuple, which is a string − if (tuple.Item2 == "Tim") { Console.WriteLine(tuple.Item2); }The following is an example to create a tuple with string and int items −using System; using System.Threading; namespace Demo { class Program { static void Main(string[] args) { ... Read More
199 Views
A delegate in C# is a reference to the method. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegate class.Let us see how to declare delegates in C# −delegate Let us see an example to learn how to work with Delegates in C# −Example Live Demousing System; using System.IO; namespace DelegateAppl { class PrintString { static FileStream fs; static StreamWriter ... Read More
605 Views
An iterator method performs a custom iteration over a collection. It uses the yield return statement and returns each element one at a time. The iterator remembers the current location and in the next iteration the next element is returned.The following is an example −Example Live Demousing System; using System.Collections.Generic; using System.Linq; namespace Demo { class Program { public static IEnumerable display() { int[] arr = new int[] {99, 45, 76}; foreach (var val in arr) { yield return val.ToString(); ... Read More
385 Views
Stack class represents a last-in, first out collection of object. It is used when you need a last-in, first-out access of items.The following is the property of Stack class −Count − Gets the number of elements in the stack.Push OperationAdd elements in the stack using the Push operation −Stack st = new Stack(); st.Push('A'); st.Push('B'); st.Push('C'); st.Push('D');Pop OperationThe Pop operation removes elements from the stack starting from the element on the top.Here is an example showing how to work with Stack class and its Push() and Pop() method −Using System; using System.Collections; namespace CollectionsApplication { class Program ... Read More
173 Views
If you want to add a comment that restricts itself to a single line, then use the single-line comments −// variable int i = 20;The following is a sample C# program showing how to add single-line comments −Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { // display text Console.WriteLine("Hello World"); Console.ReadKey(); } } }OutputHello World