Programming Articles - Page 1827 of 3366

What is the difference between int and Int32 in C#?

Nizamuddin Siddiqui
Updated on 04-Aug-2020 06:35:51

6K+ Views

Int32 is a type provided by .NET framework whereas int is an alias for Int32 in C# language.Int32 x = 5;int x = 5;So, in use both the above statements will hold a 32bit integer. They compile to the same code, so at execution time there is no difference whatsoever.The only minor difference is Int32 can be only used with System namespace. While validating the type of a value like mentioned above we can use Int32 or int.typeof(int) == typeof(Int32) == typeof(System.Int32)ExampleThe below example shows how an integer is declared using System.Int32. Live Demousing System; namespace DemoApplication{    class Program{     ... Read More

How to store n number of lists of different types in a single generic list in C#?

Nizamuddin Siddiqui
Updated on 04-Aug-2020 06:30:13

811 Views

We can store n number of lists of different types in a single generic list by creating a list of list of objects as shown below.List list = new List();Example Live Demousing System; using System.Collections.Generic; namespace MyApplication{    public class Program{       public static void Main(){          List list = new List();          List list1 = new List();          list1.Add(101);          list1.Add(102);          list1.Add(103);          list.Add(list1);          List list2 = new List();          list2.Add("Test1");   ... Read More

What is the use of "is" keyword in C#?

Nizamuddin Siddiqui
Updated on 04-Aug-2020 06:28:19

384 Views

The "is" keyword is used to check if an object can be casted to a specific type. The return type of the operation is Boolean.Exampleusing System; namespace DemoApplication{    class Program{       static void Main(){          Employee emp = new PermanentEmployee{             ID = 1,             Name = "Martin"          };          // Returns true as the derived type can be converted to base type.          if (emp is Employee){             ... Read More

What if we are not sure of the type of value that we want to store in a variable. How to handle this in C#?

Nizamuddin Siddiqui
Updated on 04-Aug-2020 06:25:55

94 Views

As C# is a strongly-typed language, every variable and constant has a pre-defined type. Before using any variable, we must tell the compiler what type of value a variable will store.If we are not sure about the type, then it is handled using dynamic programming. Dynamic programming is supported by the dynamic keyword.The dynamic keyword is used to declare dynamic types. The dynamic types tell the compiler that the object is defined as dynamic and skip type-checking at compiler time, delay type-checking until runtime. All syntaxes are checked and errors are thrown at runtime.Example Live Demousing System; namespace DemoDynamicKeyword{    class ... Read More

Maximum number of squares that can fit in a right angle isosceles triangle in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:47:45

432 Views

Given the task is to find the maximum number of squares having side ‘a’ that can fit inside a give right angle isosceles triangle with base of ‘s’(An isosceles triangle has at least 2 equal sides).Let’s now understand what we have to do using an example:Inputs=5, a=1Output10Explanation − The number of squares in the base can be calculated by dividing s by a and subtracting 1. So the number of squares in base = 5/1 – 1 = 4.Similarly when the bottom 4 squares are placed then we get a new isosceles triangle with base (s-a) and then we repeat ... Read More

Maximum number of segments that can contain the given points in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:46:29

296 Views

Given the task is to find the maximum of segments that can contain the given points.Given an array a1[] with size n1 and two integers A and B are given. From the given array a1[], n1 line segments can be formed with starting and ending points as a1[i] – A and a1[i] + B respectively.Another array a2[] is given with n2 number of points. These points have to be assigned to the line segments such that the number of line segments than have been assigned a point is maximum. Note that a single point can be assigned only once to ... Read More

Maximum number of removals of given subsequence from a string in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:43:55

241 Views

Given the task is to find the maximum number of removals of given subsequence from a string. A string s is given and we have to find the maximum number of subsequence ‘abc’ that can be removed from the string.Let’s now understand what we have to do using an example:Inputs = ‘dnabcxy’Output1Explanation − Only one subsequence of ‘abc’ can be found in the given string (‘dnabcxy’), therefore the output is 1.Inputs = ‘zcabcxabc’Output2 (‘zcabcxabc’)Approach used in the below program as followsIn Max() function initialize variables i, a, ab, abc with value = 0 and of type int.Loop from i=0 till ... Read More

Maximum number of people that can be killed with strength P in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:41:53

223 Views

Given the task is to find the maximum number of people that can be killed with strength P. Consider a row with infinite people and each of them have an index number starting from 1.The strength of the sth person is represented by s2. After killing a person with s strength your strength also decreases by s.Let’s now understand what we have to do using an example −InputP = 20Output3ExplanationStrength of 1st person = 1 * 1 = 1 < 20, therefore 1st person can be killed. Remaining strength = P – 1 = 20 – 1 = 19 Strength ... Read More

Maximum length subsequence with difference between adjacent elements as either 0 or 1 | Set 2 in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:40:47

214 Views

We are given an array of any size and the task is to find the subsequence in the given array with the elements having difference between adjacent elements as 0 or 1.Input − int arr[] = { 2, 1, 5, 6, 3, 4, 7, 6}Output − Maximum length subsequence with difference between adjacent elements as either 0 or 1 is: 3Explanation − The subsequence of adjacent elements in an array with difference as 0 or 1 are {2, 1}. Therefore, the maximum length of subsequence is 2.Input − int arr[] = { 2, 1, 7, 6, 5}Output − Maximum length ... Read More

Maximum length subsequence with difference between adjacent elements as either 0 or 1 in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:38:53

857 Views

We are given an array of any size and the task is to find the subsequence in the given array with the elements having difference between adjacent elements as 0 or 1.Input − int arr[] = { 2, 1, 5, 6, 3, 4, 7, 6}Output − Maximum length subsequence with difference between adjacent elements as either 0 or 1 is − 3Explanation − The subsequence of adjacent elements in an array with difference as 0 or 1 are {2, 1}. Therefore, the maximum length of subsequence is 2.Input − int arr[] = { 2, 1, 7, 6, 5}Output − Maximum ... Read More

Advertisements