ElementAt() is a System.Linq method in C# that is used to get and display element at a particular index.The following is our string array −string[] arr = { "One", "Two", "Three", "Four", "Five" };Now to get an element at index 0, use the ElementAt() method −arr.ElementAt(0);The following is the complete code −Example Live Demousing System.IO; using System; using System.Linq; public class Demo { public static void Main() { string[] arr = { "One", "Two", "Three", "Four", "Five" }; // displaying element at index 0 string res = arr.ElementAt(0); Console.WriteLine(res); } }OutputOne
If you want to skip a number of elements in an array, then use the Skip() method in C#.Let’s say the following is our array −int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };Now to skip first four elements −var ele = arr.Skip(4);Let us see the complete example −Example Live Demousing System.IO; using System; using System.Linq; public class Demo { public static void Main() { int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 }; Console.WriteLine("Initial Array..."); foreach (var res in arr) ... Read More
SkipWhile skips an element when a condition is matched.For example, use the following if you want to skip all even elements −ele => ele %2 == 0The following is an example wherein all the even elements are skipped and only the odd elements are displayed −Example Live Demousing System.IO; using System; using System.Linq; public class Demo { public static void Main() { int[] arr = { 20, 35, 55 }; Console.WriteLine("Initial array..."); foreach (int value in arr) { Console.WriteLine(value); } // ... Read More
Declare an array −int[] arr = { 10, 90, 20, 19, 99, 57 };Now to get the largest element from an array, use Max() method with lambda expressions −arr.Max());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { int[] arr = { 10, 90, 20, 19, 99, 57 }; Console.WriteLine(arr.Max(element => Math.Abs(element))); } }Output99
In JavaScript, the functions wrapped with parenthesis are called “Immediately Invoked Function Expressions" or "Self Executing Functions.The purpose of wrapping is to the namespace and control the visibility of member functions. It wraps the code inside a function scope and decreases clashing with other libraries. This is what we call Immediately Invoked Function Expression (IIFE) or Self Executing Anonymous Function.SyntaxHere’s the syntax −(function() { // code })();As you can see above, the following pair of parentheses converts the code inside the parentheses into an expression −function(){...}In addition, the next pair, i.e. the second pair of parentheses continues the operation. ... Read More
Use the Take() method to get the first individual number of elements in C#.Firstly, set a list and add elements −List myList = new List(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four"); myList.Add("Five"); myList.Add("Six");Now, use the Take() method to get the elements from the list. Add the number of the elements you want as an argument −myList.Take(3)Here is the code −Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { List myList = new List(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four"); ... Read More
JavaScript uses try…catch…finally to handle exceptions. The latest versions of JavaScript added exception-handling capabilities. JavaScript implements the try...catch...finally construct as well as the throw operator to handle exceptions.You can catch programmer-generated and runtime exceptions, but you cannot catch JavaScript syntax errors.SyntaxHere is the try...catch...finally block syntax − ExampleYou can try to run the following code to learn how exceptions are handled in JavaScript − Click the following to see the result:
Use the ContainsValue() method in C# to search for a value in a Dictionary.Create a Dictionary and add elements −Dictionary d = new Dictionary(); d.Add("keyboard", "One"); d.Add("mouse", "Two");Now, use the ContainsValue() method to find a particular value −d.ContainsValue("Two");The following is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { Dictionary d = new Dictionary(); d.Add("keyboard", "One"); d.Add("mouse", "Two"); // search for a value Console.WriteLine(d.ContainsValue("Two")); } }OutputTrue
Firstly, set the Dictionaries to be combined −Dictionary dict1 = new Dictionary (); dict1.Add("one", 1); dict1.Add("Two", 2); Dictionary dict2 = new Dictionary (); dict2.Add("Three", 3); dict2.Add("Four", 4);Now, use HashSet to combine them. The method used for the same purpose is UnionWith() −HashSet hSet = new HashSet (dict1.Keys); hSet.UnionWith(dict2.Keys);The following is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { Dictionary dict1 = new Dictionary (); dict1.Add("one", 1); dict1.Add("Two", 2); Dictionary ... Read More
You can try to run the following code to implement :focus pseudo-classExampleLive Demo input:focus { background-color: orange; } Subject Student: Age: Output
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP