Ankith Reddy has Published 996 Articles

How to prevent object of a class from garbage collection in Java?

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 14:30:45

286 Views

If a object is no more referenced by a live reference then it becomes eligible for garbage collection. See the example below −Examplepublic class Tester{    public static void main(String[] args) {       test();    }    public static void test(){       A a = ... Read More

How to use the Sort() method of array class in C#?

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 14:16:54

272 Views

The Sort() method sorts the elements in an entire one-dimensional Array using the IComparable implementation of each element of the Array.Set the array.int[] list = { 22, 12, 65, 9};Use the Sort() method to sort the array.Array.Sort(list);The following is an example to learn how to work with the Sort() method.Example Live ... Read More

What is the copy-and-swap idiom in C++?

Ankith Reddy

Ankith Reddy

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

326 Views

The assignment consists of 2 steps, tearing an object's old state and building a new state for it. The destructor is used for the first step and a copy constructor does the second step. Implementing both of these is straightforward. But when overloading the assignment operator, it can become quite ... Read More

How to use the GetValue() method of array class in C#?

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 12:42:50

3K+ Views

The GetValue() method of array class in C# gets the value at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.We have set the array values first using the Array.CreateInstance method.Array arr = Array.CreateInstance(typeof(String), 3, 6); arr.SetValue("One", 0, 0); arr.SetValue("Two", 0, 1); arr.SetValue("Three", 0, ... Read More

How to use StringBuilder in C#?

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 12:39:48

329 Views

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

How to use the directory class in C#?

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 12:33:42

498 Views

The Directory class in C# is used to manipulate the directory structure. It has methods to create, move, remove directories.The following are some of the methods of the Directory class.Sr.No.Method & Description1CreateDirectory(String)Creates all directories and subdirectories in the specified path2Delete(String)Deletes an empty directory3Exists(String)Whether the given path refers to an existing ... Read More

What is the best JavaScript code to create an img element?

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 12:07:26

201 Views

Try any of the following for the width of the image you want to create −myImg.setAttribute('width', '5px');OrmyImg.width = '5';OrmyImg.style.width = '5px';You can also try the following code to add the width and height to the background image −var myImg = new Image(5, 5); myImg.src = 'http://www.example.com';Read More

How do you sort an array in C# in ascending order?

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 11:43:34

10K+ Views

Firstly, set the unsorted array.int[] list = {98, 23, 97, 36, 77};Sort the array using the Sort() method.Array.Sort(list);You can try to run the following code to to sort an array in ascending order.Example Live Demousing System; namespace Demo {    public class MyApplication {       public static void Main(string[] ... Read More

What is the scope of a protected member variable of a class in C#?

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 11:36:24

479 Views

Protected access specifier allows a child class to access the member variables and member functions of its base class. This way it helps in implementing inheritance. We will discuss this in more details in the inheritance chapter.The following is an example showing we have set an protected member variable in ... Read More

C# program to find maximum and minimum element in an array

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 11:35:29

7K+ Views

Set the minimum and maximum element to the first element so that you can compare all the elements.For maximum.if(arr[i]>max) {    max = arr[i]; }For minimum.if(arr[i]

Advertisements