Chandu yadav has Published 1091 Articles

Set the navigation bar to stay at the top of the web page with CSS

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:55:13

253 Views

To set the navigation bar at top, use position: fixed property, with top property.You can try to run the following code to implement a menu that stays on the top, ExampleLive Demo                    ul {             ... Read More

How to prevent Reflection to break a Singleton Class Pattern?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:43:37

898 Views

A Singleton pattern states that a class can have a single instance and multiple instances are not permitted to be created. For this purpose, we make the constructor of the class a private and return a instance via a static method. But using reflection, we can still create multiple instance ... Read More

How do we access elements from the two-dimensional array in C#?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:23:36

3K+ Views

A 2-dimensional array can be thought of as a table, which has x number of rows and y number of columns.An element in 2-dimensional array is accessed by using the subscripts. That is, row index and column index of the array.int x = a[1, 1]; Console.WriteLine(x);Let us see an example ... Read More

How to sort one-dimensional array in ascending order using non-static method?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:20:04

2K+ Views

Set the unsorted array first.int[] list = {87, 45, 56, 22, 84, 65};Now use a nested for loop to sort the list, which is passed to a function.for(int i=0; i< arr.Length; i++) {    for(int j=i+1; j=arr[j]) {          temp=arr[j];          arr[j]=arr[i];     ... Read More

How to use WriteLine() method of Console class in C#?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:13:17

366 Views

WriteLine() is a method of the Console class defined in the System namespaceThis statement causes the message "Welcome!" to be displayed on the screen as shown below −Example Live Demousing System; namespace Demo {    class Test {       static void Main(string[] args) {          Console.WriteLine("Welcome!"); ... Read More

How to workaround Objects vs arrays in JavaScript for key/value pairs?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 13:21:48

186 Views

Store it like the following −var players = {    600 : 'Sachin',    300 : 'Brad', };For key/ value pairs, we have used the above solution, since we wanted a one-to-one. We did this to use the key as a lookup key. You can also add more values like ... Read More

What's the best way to detect a 'touch screen' device using JavaScript?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 13:08:10

717 Views

The best way to detect a ‘touch screen’ device, is to work around to see whether the touch methods are present within the document model or not.function checkTouchDevice() {    return 'ontouchstart' in document.documentElement; }Here, you can also use it to detect mobile or desktop, like the following −if (checkTouchDevice()) ... Read More

How to sort a list in C#?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 12:46:20

234 Views

Set a list with some values. Here, we have a list of strings.var cars = new List() {"Mercedes", "Audi", "Jaguar" };To sort, simply use Sort() method.cars.Sort();The following is an example showing how to sort a list in C#.Example Live Demousing System; using System.Collections.Generic; public class Program {    public static void ... Read More

How to use the Clear method of array class in C#?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 12:36:43

303 Views

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 ... Read More

What are Base and Derived Classes in C#?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 12:29:37

281 Views

A class can be derived from more than one class or interface, which means that it can inherit data and functions from multiple base classes or interfaces.For example, Vehicle Base class with the following Derived Classes.Truck Bus MotobikeThe derived class inherits the base class member variables and member methods.In the ... Read More

Advertisements