The IndexOf() method of array class in C# searches for the specified object and returns the index of the first occurrence within the entire one-dimensional Array.We have set the array.int[] arr = new int[10]; arr[0] = 100; arr[1] = 200; arr[2] = 300; arr[3] = 400; arr[4] = 500; arr[5] = 600; arr[6] = 700; arr[7] = 800; arr[8] = 900; arr[9] = 1000;Now use the IndexOf() method and set the element for which you want the index, for example, I have set it for element 800.int a = Array.IndexOf(arr, 800);The following is the example showing the usage of IndexOf(, ... Read More
A main method is static since it is available to run when the C# program starts. It is the entry point of the program and runs without even creating an instance of the class.The Main method states what the class does when executed and instantiates other objects and variables.The following shows how to add a Main() method.Exampleusing system; namespace demo { class helloworld { static void main(string[] args) { console.writeline("hello world"); console.readkey(); } } }As you can see in the above example.static void Main(string[] ... Read More
The return statement is used to return value. When a program calls a function, the program control is transferred to the called function. A called function performs a defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns the program control back to the main program.The following is an example to learn about the usage of return statement in C#. Here, we are finding the factorial of a number and returning the result using the return statement.while (n != 1) { res = res * n; n = n ... Read More
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#.
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
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
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
To set the brightness, use the brightness property and for contrast, use the contrast property.ExampleYou can try to run the following code to use image filters with JavaScript −Live Demo Click below to change the brightness and contrast of the image. Edit Image function display() { document.getElementById("myID").style.filter = "brightness(50%)"; document.getElementById("myID").style.filter = "contrast(50%)"; }
Use the pageBreakAfter property in JavaScript to set the page-break behavior after an element. Use the always property for page after an element.Note − The changes would be visible while printing or viewing the print preview.ExampleYou can try to run the following code to return the page-break behavior after an element with JavaScript − Heading 1 This is demo text. This is demo text. This if footer text. Set page-break function display() { document.getElementById("myFooter").style.pageBreakAfter = "always"; }
Use the pageBreakInside property in JavaScript to set the page-break behavior inside an element. Use the auto property to insert page break inside an element. Use auto or avoid property value to automatically insert page break inside an element, if needed, or avoid a page break, respectively.Note − The changes would be visible while printing or viewing the print preview.ExampleYou can try to run the following code to return the page-break behavior inside an element with JavaScript − Heading 1 This is demo text. This is demo text. This ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP