Samual Sam has Published 2492 Articles

How to add integer values to a C# list?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 14:58:47

7K+ Views

To add integer values to a list in C#, use the Add() method.Firstly, declare an integer list in C# −List list1 = new List();Now add integer values −list1.Add(900); list1.Add(400); list1.Add(300);Let us see the complete code −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Demo {    public class ... Read More

How to add read-only property in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 14:47:38

188 Views

A field marked "read-only", can only be set once during the construction of an object. It cannot be changed −Let us see an example.class Employee {    readonly int salary;    Employee(int salary) {       this.salary = salary;    }    void UpdateSalary() {     ... Read More

How to create a Directory using C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 14:00:14

251 Views

To create, move and delete directories in C#, the System.IO.Directory class has methods.Firstly, import the System.IO namespace.Now, use the Director.CreateDirectory() method to create a directory in the specified path −string myDir = @"D:\NEW"; if (!Directory.Exists(myDir)) {    Directory.CreateDirectory(myDir); }In the same way, you can create a sub-directory −string mysubdir = ... Read More

How to compare two lists for equality in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 13:44:24

2K+ Views

Set the two lists −List OneList < string > list1 = new List < string > (); list1.Add("A"); list1.Add("B"); list1.Add("C"); list1.Add("D");List TwoList < string > list2 = new List < string > (); list2.Add("C"); list2.Add("D");Now if the following returns different elements, then it would mean the lists are not equal ... Read More

What is the difference between function overriding and method hiding in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 13:36:43

520 Views

OverridingUnder overriding, you can define a behavior that's specific to the subclass type, which means a subclass can implement a parent class method based on its requirement.Let us see an example of abstract classes that implements Overriding −Exampleusing System; namespace PolymorphismApplication {    abstract class Shape {     ... Read More

How are the methods and properties of Array class in C# useful?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 13:32:46

358 Views

The Array class is the base class for all the arrays in C#. It is defined in the System namespace.The following are the methods of the Array class in C# −Sr.NoMethod & Description1ClearSets a range of elements in the Array to zero, to false, or to null, depending on the ... Read More

How to compare two arrays in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 13:26:44

994 Views

Firstly, set the two arrays to be compared −// two arrays int[] arr = new int[] { 99, 87, 56, 45}; int[] brr = new int[] { 99, 87, 56, 45 };Now, use SequenceEqual() to compare the two arrays −arr.SequenceEqual(brr);The following is the code to compare two arrays −Exampleusing System; ... Read More

How to convert Trigonometric Angles in Radians using C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 13:13:04

3K+ Views

To convert trigonometric angles in Radians, multiply by Math.PI/180. This will convert degrees to radians.The following is the code −Exampleusing System; class Program {    static void Main() {       Console.WriteLine(Math.Cos(45));       double res = Math.Cos(Math.PI * 45 / 180.0);       Console.WriteLine(res); ... Read More

How to access elements from jagged array in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 12:58:11

559 Views

A Jagged array is an array of arrays. To access an element from it, just mention the index for that particular array.Here, we have a jagged array with 5 array of integers −int[][] a = new int[][]{new int[]{0, 0}, new int[]{1, 2}, new int[]{2, 4}, new int[]{ 3, 6 }, ... Read More

What is a reference/ref parameter of an array type in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 12:50:17

956 Views

Declare the reference parameters using the ref keyword. A reference parameter is a reference to a memory location of a variable. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters.Declare a ref parameter −public void swap(ref int x, ref int ... Read More

Advertisements