Firstly, set the unsorted array.int[] list = {98, 23, 97, 36, 77};Sort the array using the Sort() method.Array.Sort(list);You can try to run the following code to to sort an array in ascending 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) { Console.Write(i + " "); } Array.Sort(list); Console.WriteLine("Sorted List"); for(int i=0; i
To compress and decompress files using GZIP Format, use the GZipStream class.CompressTo zip a file, use the GZipStream class with the FileStream class. Set the following parameters.File to be zipped and the name of the output zip file.Here, outputFile is the output file and the file is read into the FileStream.Exampleusing(var compress = new GZipStream(outputFile, CompressionMode.Compress, false)) { byte[] b = new byte[inFile.Length]; int read = inFile.Read(b, 0, b.Length); while (read > 0) { compress.Write(b, 0, read); read = inFile.Read(b, 0, b.Length); } }DecompressTo decompress a file, use the same ... Read More
The for each loop similar to the for loop; however, the loop is executed for each element in an array or group. Therefore, the index does not exist in foreach loop.Let us see an example of Bubble Sort, wherein after sorting the elements, we will display the elements using the foreach loop.foreach (int p in arr) Console.Write(p + " ");The following is the complete example.Example Live Demousing System; namespace BubbleSort { class MySort { static void Main(string[] args) { int[] arr = { 78, 55, 45, 98, 13 }; int temp; for (int j = 0; j
Methods and Functions are the same in C#.However, Methods are used in C# and are functions that operate through a designated class. A method is a group of statements that together perform a task. Every C# program has at least one class with a method named Main.The following is a simple example showing how to create methods in C#.Exampleclass NumberManipulator { public int FindMax(int num1, int num2) { /* local variable declaration */ int result; if (num1 > num2) { result = num1; }else { result = num2; } return result; } ... }
To set the duration for an effect to complete, use the transitionDuration property in JavaScript.ExampleYou can try to run the following code to return how many seconds or milliseconds a transition effect takes to complete − #div1 { position: relative; margin: 10px; height: 300px; width: 400px; padding: 20px; border: 2px solid blue; } #div2 { padding: 80px; position: absolute; border: 2px solid BLUE; background-color: yellow; transform: rotateY(45deg); transition: all 5s; } #div2:hover { background-color: orange; width: 50px; height: 50px; padding: 100px; border-radius: 50px; } Hover over DIV2 Set DIV1 DIV2 function display() { document.getElementById("myDIV").style.transitionDuration = "5s"; }
C# allows multidimensional arrays. Declare a 2-dimensional array of int as.int [ , , ] a;The simplest form of the multidimensional array is the 2-dimensional array. A 2-dimensional array is a list of one-dimensional arrays.The following is a two-dimensional array with 3 rows and 4 columns.Let us now see an example to work with multi-dimensional arrays in C#.Example Live Demousing System; namespace ArrayApplication { class MyArray { static void Main(string[] args) { /* an array with 5 rows and 2 columns*/ int[, ] a = new int[5, 2] {{0, ... Read More
A sorted list is a combination of an array and a hash table. It contains a list of items that can be accessed using a key or an index.Gets and sets the value associated with a specific key in the SortedList.You can also use the Item property to add new elements.If a key does not exist, then you can include it like.myCollection["myNonexistentKey"] = myValueIf the key already exist, then it will overwrite it with the new key and value.The following is an example to learn how to work with Item property of SorteList class in C#.Example Live Demousing System; using System.Collections; ... Read More
To set all the border top properties in a single declaration, use the borderTop property. With this property, you can set the border-top-width, border-top-style, and border-top-color property.ExampleYou can try to run the following code to learn how to work with border-top properties in JavaScript −Live Demo #box { border: thick solid gray; width: 300px; height: 200px } Demo Text Change top border function display() { document.getElementById("box").style.borderTop = "thick solid #000000"; }
The protected internal access specifier allows a class to hide its member variables and member functions from other class objects and functions, except a child class within the same application.In the below example, the derived class object can access the protected internal variable.Example Live Demousing System; class One { protected internal int a = 50; private int b; } class Two : One { public Two() { Console.WriteLine(this.a); } } class Demo { static void Main() { Two t = new Two(); // allowed since it is a derived class object t.a = 20; } }Output50
Firstly, declare and initialize two numbers.int num1 = 35; int num2 = 55;With that, use if- else to find the minimum number.if (num1 < num2) { minNum = num1; } else { minNum = num2; }Above, we have set the minimum value to the variable minNum and printed it later on.The following is the complete example to find minimum between 2 numbers in C#.Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { int num1 = 50; int num2 = 90; ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP