Programming Articles - Page 1189 of 3363

What is the usage of ref, out, and in keywords in C#?

Akshay Khot
Updated on 19-May-2021 07:41:00

592 Views

In C#, most of the methods can have zero or more parameters which define the data that must be provided to the method. Any code that calls the method has to pass the data (called arguments) to the method. A method declares its inputs as parameters, and they're provided by calling code in the form of arguments.For example, consider the following method and subsequent method call.static void Greet(string greeting){    Console.WriteLine(greeting); } ... Greet("Hello");In the above example, greeting is a parameter of the Greet() method, and "Hello" is an argument passed to the method.When you call a method and pass ... Read More

Provide a brief overview of the C# and .NET ecosystem

Akshay Khot
Updated on 19-May-2021 07:40:00

716 Views

C# is an object-oriented, type-safe and general-purpose programming language, which focuses on making the programmers productive. It tries to achieve this productivity through expressiveness, simplicity and a focus on performance. It works on different platforms such as Windows, Mac, and Linux.Type-SafetyC# is a statically typed language. That means the types are verified when you compile a program. This eliminates a large set of errors before the program even runs.Garbage CollectionAutomatic memory management is an essential feature of C#. It has a garbage collector that runs along with the programs, reclaiming the unused memory. This frees the burden from programmers to ... Read More

Explain and contrast value types and reference types in C#

Akshay Khot
Updated on 19-May-2021 07:33:11

366 Views

In general, all types in C# can be divided into two main categories − value types and reference types. Let's look at each type in detail.Value TypesVariables of value types directly contain their data. Each variable has its own copy of the data. Hence it is impossible for a variable of value type to modify another object.A value type can be one of the following types −all numeric types, e.g., int, float, and doublechar and the bool typesstruct type orenumeration type.A value type simple contains the value. For example, the integer type contains the actual number, and not a pointer ... Read More

Program to find out the dot product of two sparse vectors in Python

Arnab Chakraborty
Updated on 18-May-2021 12:14:56

721 Views

Suppose, we have two sparse vectors represented in two lists. We have to return the dot product of the two sparse vectors. The vectors are represented as objects, and the lists are stored in a member variable 'nums' in the objects.So, if the input is like vector1 = [1, 0, 0, 0, 1], vector2 = [0, 0, 0, 1, 1], then the output will be 1 The dot product is 1 * 0 + 0 * 0 + 0 * 0 + 0 * 1 + 1 * 1 = 1.To solve this, we will follow these steps −res := ... Read More

Program to find out the number of boxes to be put into the godown in Python

Arnab Chakraborty
Updated on 18-May-2021 12:14:14

389 Views

Suppose, we have two arrays containing integers. One list contains the height of some unit width boxes and another array contains the height of rooms in the godown. The rooms are numbered 0...n, and the height of the rooms is provided in their respective indexes in the array godown. We have to find out the number of boxes that can be pushed into the godown. a few things have to be kept in mind, The boxes can’t be put one on another.The order of the boxes can be changed.The boxes are put into the godown from left to right only.If ... Read More

Program to find out if the strings supplied differ by a character in the same position in Python

Arnab Chakraborty
Updated on 18-May-2021 12:12:02

203 Views

Suppose, we are provided an array that contains several strings that are of the same length. We have to find out if any two of the supplied strings differ by a single character at the same position. If this difference is present, we return true or else we return false.So, if the input is like dict = ['pqrs', 'prqs', 'paqs'], then the output will be True. The output produced is True because the strings listed in the input all differ in index 1. So, if any two pairs are taken, there is a difference in the same position.To solve this, ... Read More

Program to find out the index of the most frequent element in a concealed array in Python

Arnab Chakraborty
Updated on 18-May-2021 12:08:02

279 Views

Suppose, we are given a class called 'TestArray' that contains an private array which can only contain values 0 or 1; and two public member functions length() and query(). The function length() returns the length of the array and the function query() returns three different values comparing various values in the array. The function takes four values p, q, r, s as input and works like this −if all the four values in the given indexes of the array are either 0 or 1, it returns 4.else if any three values in the given indexes of the array are the ... Read More

Program to find out the index in an array where the largest element is situated in Python

Arnab Chakraborty
Updated on 18-May-2021 12:06:41

231 Views

Suppose, we are given a class called 'TestArray' that contains an array that is not accessible by other classes and two public member functions length() and compare(). The function length() returns the length of the array and the function compare() returns three different values comparing various subarrays from the array. The function takes four values l, r, x, y as input and works like this −if (array[l] + array[l+1]+......+array[r-1]+array[r]) > (array[x] + array[x+1]+......+array[y1]+array[y]); it returns 1if (array[l] + array[l+1]+......+array[r-1]+array[r]) = (array[x] + array[x+1]+......+array[y1]+array[y]); it returns 0if (array[l] + array[l+1]+......+array[r-1]+array[r]) < (array[x] + array[x+1]+......+array[y1]+array[y]); it returns -1We have to find out ... Read More

Program to find the diameter of a n-ary tree in Python

Arnab Chakraborty
Updated on 18-May-2021 12:05:16

423 Views

Suppose, we are given an n-ary tree and said to determine the diameter of the tree. The diameter of the tree is the longest path that is present between any two leaf nodes of the tree. We have to find out and return the integer value that represents the diameter of the tree.So, if the input is likethen the output will be 3.The diameter of this n-ary tree consists of the edges 27->14, 14->42, and 42->56 or 42->65 (marked in the diagram by red lines). The path length is 3.To solve this, we will follow these steps −ans := 1Define ... Read More

Program to find the root of a n-ary tree in Python

Arnab Chakraborty
Updated on 18-May-2021 12:04:53

648 Views

Suppose, we are given the nodes of an n-ary tree in an array. We have to find and return the root node of the tree by reconstructing it. The full tree has to be displayed from the returned node in preorder notation.So, if the input is likethen the output will be[14, 27, 32, 42, 56, 65]We will use the root of the tree to display the pre order traversal of the tree. So, the output is a pre order traversal of the tree.To solve this, we will follow these steps −indegree := a new map containing integer valuesfor each node ... Read More

Advertisements