Arjun Thakur has Published 1025 Articles

What are all the possible C# array initialization syntaxes?

Arjun Thakur

Arjun Thakur

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

112 Views

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

Difference between window.location.href, window.location.replace and window.location.assign in JavaScript?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 12:14:47

626 Views

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

How to create an infinite loop in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 12:10:34

1K+ Views

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

How to create a JavaScript code for multiple keys pressed at once?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 11:59:51

655 Views

Use the keydown event in JavaScript to get to know which keys are pressed at once. The following is the script −Examplevar log = $('#log')[0],    keyPressed = []; $(document.body).keydown(function (evt) {    var li = keyPressed [evt.keyCode];    if (!li) {       li = log.appendChild(document.createElement('li'));     ... Read More

How to initialize two-dimensional arrays in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 11:28:14

23K+ Views

A 2-dimensional array is a list of one-dimensional arrays.Two-dimensional arrays may be initialized by specifying bracketed values for each row.int [, ] a = new int [4, 4] {    {0, 1, 2, 3} ,    {4, 5, 6, 7} ,    {8, 9, 10, 11} ,    {12, 13, ... Read More

What is the Item property of Hashtable class in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 11:21:41

112 Views

Gets or sets the value associated with the specified key. You can also use the Item property to add new elements.If a key does not exist, then you can include it like −myCollection["myNonexistentKey"] = myValueThe following is the code showing how to work with Item property of Hashtable class in ... Read More

What is the Keys property of SortedList class in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 10:49:39

99 Views

Get the keys in the SortedList using the keys property of SortedList class in C#. We have first set the SortedList property with elements.SortedList sl = new SortedList(); sl.Add("ST0", "One"); sl.Add("ST1", "Two"); sl.Add("ST2", "Three"); sl.Add("ST3", "Four"); sl.Add("ST4", "Five"); sl.Add("ST5", "Six"); sl.Add("ST6", "Seven");Now use the keys property to get the keys.ICollection ... Read More

What is the IsReadOnly property of SortedList class in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 10:03:48

108 Views

Use the IsReadOnly property to get a value indicating whether the SortedList is read-only or not.You can try to run the following code to implement IsReadOnly property in C#.Here, we have set the SortedList first.SortedList s = new SortedList();Added elements.s.Add("S001", "Jack"); s.Add("S002", "Henry");Now check for IsReadOnly.Console.WriteLine("IsReadOnly = " + s.IsReadOnly);The ... Read More

C# Nested Classes

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 09:54:58

2K+ Views

A nested class is a class declared in another enclosing class. It is a member of its enclosing class and the members of an enclosing class have no access to members of a nested class.Let us see an example code snippet of nested classes in C#.Exampleclass One {    public ... Read More

C# program to replace n-th character from a given index in a string

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 09:43:40

2K+ Views

Firstly, set a string.string str1 = "Port"; Console.WriteLine("Original String: "+str1);Now convert the string into character array.char[] ch = str1.ToCharArray();Set the character you want to replace with the index of the location. To set a character at position 3rd.ch[2] = 'F';To remove nth character from a string, try the following C# ... Read More

Advertisements