Chandu yadav has Published 1090 Articles

How to prevent Reflection to break a Singleton Class Pattern?

Chandu yadav

Chandu yadav

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

909 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

375 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

190 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

728 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

242 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

315 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

287 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

What are accessors of properties in C#?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 12:18:13

888 Views

Properties are an extension of fields and are accessed using the same syntax. They use accessors through which the values of the private fields can be read, written or manipulated.The accessor of a property contains the executable statements that helps in getting (reading or computing) or setting (writing) the property.Let ... Read More

Advertisements