The List is a collection in C# and is a generic collection. The add and remove methods are used in C# lists for adding and removing elements.Let us see how to use Add() method in C#.Example Live Demousing System; using System.Collections.Generic; class Program { static void Main() { List sports = new List(); sports.Add("Football"); sports.Add("Tennis"); sports.Add("Soccer"); foreach (string s in sports) { Console.WriteLine(s); } } }OutputFootball Tennis SoccerLet us see how to use Remove() method in C#.Example Live ... Read More
To set the column width and column count in a single declaration, use the JavaScript columns property.ExampleYou can try to run the following code to set column width and column count with JavaScript − #myID { column-count: 4; column-rule: 4px solid yellow; } Click below to change the column count to 2 and minimum size Change Column count and ... Read More
Array can be initialized in more than one ways in C#. Let us see some example.Method OneUsing size of array.int [] marks = new int[5] { 99, 98, 92, 97, 95};Method TwoBy omitting the size.int [] marks = new int[] { 99, 98, 92, 97, 95};Method ThreeInitializing at the time of declaration.int [] marks = { 99, 98, 92, 97, 95};Let us see one of the ways to initialize arrays in C#.Example Live Demousing System; namespace Demo { class MyArray { static void Main(string[] args) { int [] n = new int[10]; /* ... Read More
Use the flex property in JavaScript to set the length of the item relative to the rest. You can try to run the following code to implement flex property with JavaScript −Example #box { border: 1px solid #000000; width: 300px; height: 400px; display: flex; } DIV1 DIV2 DIV3 Set function display() { var a = document.getElementById("box"); var b = a.getElementsByTagName("DIV"); var j ; for (j = 0; j < b.length; j++) { b[j].style.flex = "1"; } }
The window object includes the location object in JavaScript. It includes the following properties −window.location.hrefIt returns the URL of the current page.Example Click below to get the complete URL of the page. URL function display() { var res = location.href; document.write(res); } window.location.replaceIt is used to replace the current document.Example Replace current document function display() { location.replace("https://www.qries.com") } window.location.assignIf you want to load a new document, use JavaScript assign.Example Open new document function display() { location.assign("https://www.qries.com") }
Firstly, declare and initialize two numbers.int num1 = 50; int num2 = 90;With that, use if-else to find the maximum number.if (num1 > num2) { maxNum = num1; } else { maxNum = num2; }Above, we have set the maximum value to the variable maxNum and printed it later on.The following is the complete example to find maximum 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
Threads are lightweight processes. A thread is defined as the execution path of a program. Threads are created by extending the Thread class. The extended Thread class then calls the Start() method to begin the child thread execution.Example of Thread: One common example of use of thread is implementation of concurrent programming by modern operating systems. Use of threads saves wastage of CPU cycle and increase efficiency of an application.The following is an example showing how to create a thread.Example Live Demousing System; using System.Threading; namespace Demo { class Program { public static void ThreadFunc() { ... Read More
Firstly, set two items in the tuple.Tuple tuple = new Tuple(20, "Tom");Now check for first item in the tuple, which is an integer.if (tuple.Item1 == 20) { Console.WriteLine(tuple.Item1); }Now check for second item in the tuple, which is a string −if (tuple.Item2 == "Tom") { Console.WriteLine(tuple.Item2); }The following is an example to create a tuple with string and int items.Example Live Demousing System; using System.Threading; namespace Demo { class Program { static void Main(string[] args) { Tuple tuple = new Tuple(20, "Tom"); if (tuple.Item1 == 20) { ... Read More
An infinite loop is a loop that never terminates and repeats indefinitely.Let us see an example to create an infinite loop in C#.Exampleusing System; namespace Demo { class Program { static void Main(string[] args) { for (int a = 0; a < 50; a--) { Console.WriteLine("value : {0}", a); } Console.ReadLine(); } } }Above, the loop executes until a < 50. The value of is set to 0 initially.int a = 0;The value of a decrements after each iteration since it is set to.a--;Therefore the value of a will never be above 50 and the condition a
Dynamic arrays are growable arrays and have an advantage over static arrays. This is because the size of an array is fixed.To create arrays dynamically in C#, use the ArrayList collection. It represents ordered collection of an object that can be indexed individually. It also allows dynamic memory allocation, adding, searching and sorting items in the list.The following is an example showing how to create arrays in dynamically in C#.Example Live Demousing System; using System.Collections; namespace CollectionApplication { class Program { static void Main(string[] args) { ArrayList al = new ArrayList(); ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP