Samual Sam has Published 2310 Articles

C# Numeric Promotion for Conditional Expression

Samual Sam

Samual Sam

Updated on 21-Jun-2020 15:30:41

143 Views

Numeric promotion is the promotion of smaller types to larger types like short to int.In the below example, we have seen a numeric promotion in Conditional Expression.The short types are automatically promoted to larger type int.Exampleusing System; class Program {    static void Main() {       short ... Read More

Why does the indexing start with zero in C# arrays?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 15:26:30

1K+ Views

Arrays were a pointer to an address in memory of the index. This index was the 1st element of the array. Here, the index is like an offset and the concept even before C language originated.Let’s say your array elements begins from 0Xff000 and has 5 elements like {35, 23, ... Read More

Final local variables in C#

Samual Sam

Samual Sam

Updated on 21-Jun-2020 15:19:47

2K+ Views

To set final for a local variable, use the read-only keyword in C#, since the implementation of the final keyword is not possible.The readonly would allow the variables to be assigned a value only once. A field marked "read-only", can only be set once during the construction of an object. ... Read More

What are the differences between a multi-dimensional array and jagged array?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 15:13:59

1K+ Views

Multi-dimensional arrayMulti-dimensional arrays are also called rectangular array. You can define a 3-dimensional array of integer as −int [ , , ] val;Let us see how to define a two-dimensional array.int[, ] val = new[3, 3] Jagged arrayA Jagged array is an array of arrays. To access an element from ... Read More

How to copy or clone a C# list?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 15:06:41

3K+ Views

To copy or clone a C# list, firstly set a list −List < string > list1 = new List < string > (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four");Now declare a string array and use the CopyTo() method to copy.string[] arr = new string[20]; list1.CopyTo(arr);Let us see the complete code to copy ... Read More

What is the difference between implicit and explicit type conversion in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 15:03:14

923 Views

The following is the difference between implicit and explicit type conversion −Implicit Type ConversionThese conversions are performed by C# in a type-safe manner.To understand the concept, let us implicitly convert int to long.int val1 = 11000; int val2 = 35600; long sum; sum = val1 + val2;Above, we have ... Read More

How to add integer values to a C# list?

Samual Sam

Samual Sam

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

9K+ 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

305 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

428 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

Advertisements