The length property is used to gets or sets the number of elements in the BitArray.Our BitArray.BitArray arr = new BitArray( 5 );To calculate the length, use the length property.Console.WriteLine( "Length: {0}", arr.Length );You can try to run the following code to learn how to work with Length property of BitArray class.Example Live Demousing System; using System.Collections; public class Demo { public static void Main() { BitArray arr = new BitArray( 5 ); Console.WriteLine( "Count: {0}", arr.Count ); Console.WriteLine( "Length: {0}", arr.Length ); } }OutputCount: 5 Length: 5
To initializes a string in C# is an easy task. Let’s say you want to set a name “Amit”, for that, initialize your string as.String str1 = "Hello, World!";To compare strings, use the the following C# method.public static int Compare(string str1, string str2)To compare, if −String.Compare(str1, str2) == 0If the above is equal to 0, then both the strings are equal.The above method compares two specified string objects and returns an integer that indicates their relative position in the sort order.The following is an example that shows the comparison of one string to another.Example Live Demousing System; namespace Demo { ... Read More
To divide a div into three columns, use the columnCount property. Set the column count and divide the div.ExampleYou can try to run the following code to return the numbers of columns an element is to be divided into with JavaScript −Live Demo Click below to create 4 columns Columns This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This ... Read More
Use the wordWrap property in JavaScript to allow long words to be broken and wrap to the next line.ExampleYou can try to run the following to learn how to work with wordWrap property − #box { width: 150px; height: 150px; background-color: lightblue; border: 1px solid black; } Set ThisisDemoText.ThisisDemoText.ThisisDemoText.ThisisDemoText.Thisis DemoText.ThisisDemoText. function display() { document.getElementById("box").style.wordWrap = "break-word"; }
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP