Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2411 of 2646
249 Views
Set a list with some values. Here, we have a list of strings.var cars = new List() {"Mercedes", "Audi", "Jaguar" };To sort, simply use Sort() method.cars.Sort();The following is an example showing how to sort a list in C#.Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { var cars = new List() {"Mercedes", "Audi", "Jaguar" }; Console.WriteLine("Original Array ="); foreach (var name in cars) { Console.WriteLine(name); } // sort cars.Sort(); ... Read More
500 Views
The GetLowerBound() method of array class in C# gets the lower bound of the specified dimension in the Array.Firstly, set the array and get the lower bound as shown below −arr.GetLowerBound(0).ToString()The following is an example stating the usage of GetLowerBound() method in C#.Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace lower { class Program { static void Main(string[] args) { Array arr = Array.CreateInstance(typeof(String), 3); arr.SetValue("Car", 0); arr.SetValue("Truck", 1); arr.SetValue("Motorbike", 2); Console.WriteLine("Lower Bound {0}",arr.GetLowerBound(0).ToString()); Console.ReadLine(); } } }OutputLower Bound 0
373 Views
The GetLongLength method in C# gets a 64-bit integer that represents the number of elements in the specified dimension of the Array.First, set the array.long[,] arr2= new long[15, 35];For a specified dimension of the array, set the index in the GetLongMethod() method like −long len2 = arr2.GetLongLength(0);Let us see the complete example.Example Live Demousing System; class Program { static void Main() { int[,] arr = new int[20, 30]; int len = arr.GetLength(0); Console.WriteLine(len); long[,] arr2= new long[15, 35]; long len2 = arr2.GetLongLength(0); Console.WriteLine(len2); } }Output20 15
526 Views
The Directory class in C# is used to manipulate the directory structure. It has methods to create, move, remove directories.The following are some of the methods of the Directory class.Sr.No.Method & Description1CreateDirectory(String)Creates all directories and subdirectories in the specified path2Delete(String)Deletes an empty directory3Exists(String)Whether the given path refers to an existing directory4GetCreationTime(String)Gets the creation date and time of a directory.5GetCurrentDirectory()Gets the current working directory6GetFiles(String)Let us learn about the usage of GetFiles() method in Directory class. It displays all the files in the specified directory.Exampleusing System; using System.IO; class Program { static void Main() { // Get all ... Read More
415 Views
As the name suggests the Array.Copy() method in C# is used to copy elements of one array to another array.The following is the syntax.Array.Copy(src, dest, length);Heresrc = array to be copieddest = destination arraylength = how many elements to copyThe following is an example showing the usage of Copy(,,) method of array class in C#.Example Live Demousing System; class Program { static void Main() { int[] arrSource = new int[4]; arrSource[0] = 99; arrSource[1] = 66; arrSource[2] = 111; arrSource[3] = 33; int[] arrTarget = new int[4]; Array.Copy(arrSource, arrTarget, 4); Console.WriteLine("Destination Array ..."); foreach (int value in arrTarget) { Console.WriteLine(value); } } }OutputDestination Array ... 99 66 111 33
332 Views
The Array.Clear class in C# clears i.e.zeros out all elements.In the below example, we have first considered an array with 3 elements.int[] arr = new int[] { 11, 40, 20};Now we have used the Array.clear method to zero out all the arrays.Array.Clear(arr, 0, arr.Length);Let us see an example of Array.clear method in c#.Example Live Demousing System; class Program { static void Main() { int[] arr = new int[] {11, 40, 20}; Console.WriteLine("Array (Old):"); foreach (int val in arr) { Console.WriteLine(val); } ... Read More
353 Views
A conditional operator is represented by the symbol '?:' The first operand is the evaluating expression. It has right to left associativity.The syntax for conditional operator.expression ? expression : expressionThe conditional operator works as follows −The first operand is implicitly converted to bool.If the first operand evaluates to true, the second operand is evaluated.If the first operand evaluates to false, the third operand is evaluated.Remember, only one of the last two operands is evaluated in a conditional expression.Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { int ... Read More
265 Views
The following is the unsorted array.int[] list = {98, 23, 97, 36, 77};Now first use the Sort() method to sort the array.Array.Reverse(list);Use the Reverse() method that would eventually give you a sorted array in descending order.Array.Reverse(list);You can try to run the following code to to sort one dimensional array in descending order.Example Live Demousing System; namespace Demo { public class MyApplication { public static void Main(string[] args) { int[] list = {98, 23, 97, 36, 77}; Console.WriteLine("Original Unsorted List"); foreach (int i in list) { ... Read More
342 Views
With StringBuilder, you can expand the number of characters in the string. String cannot be changed once it is created, but StringBuildercan be expanded. It does not create a new object in the memory.Initialize StringBuilder.StringBuilder str = new StringBuilder();Let us see an example to learn how to work with StringBuilder in C#.Example Live Demousing System; using System.Text; public class Program { public static void Main() { StringBuilder str = new StringBuilder("Web World!!",30); str.Replace("World", "Arena"); Console.WriteLine(str); } }OutputWeb Arena!!Above the Replace() method of StringBuilder is used to to replace a string in C#.
195 Views
For the Boolean type, the bool keyword is used and is an alias of System.Boolean.It is used to declare variables to store the Boolean values, true and false.Let us see an example to learn how to use bool in C#.Exampleusing System; public class Demo { static void Main() { bool val = true; int d = DateTime.Now.DayOfYear; val = (d % 2 == 0); if (val) { Console.WriteLine("days: even number"); } else { Console.WriteLine("days:odd number"); } } }