Samual Sam has Published 2492 Articles

String format for DateTime in C#

Samual Sam

Samual Sam

Updated on 21-Jun-2020 15:54:17

336 Views

Format DateTime using String.Format method.Let us see an example −Exampleusing System; static class Demo {    static void Main() {       DateTime d = new DateTime(2018, 2, 8, 12, 7, 7, 123);       Console.WriteLine(String.Format("{0:y yy yyy yyyy}", d));       Console.WriteLine(String.Format("{0:M MM MMM ... Read More

How to add an item to an ArrayList in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 15:51:25

141 Views

ArrayList is a non-generic type of collection in C# that dynamically resizes.Let us see how to initialize ArrayList in C# −ArrayList arr= new ArrayList();Add an item to an Array List −ArrayList arr1 = new ArrayList(); arr1.Add(30); arr1.Add(70);Let us see the complete example to implement ArrayList in C#. Here we have ... Read More

Final variables in C#

Samual Sam

Samual Sam

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

3K+ Views

Java has a final keyword, but C# does not have its implementation. Use the sealed or readonly keyword in C# for the same implementation.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 ... Read More

What are the differences between a class and struct in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 15:36:52

548 Views

ClassClass is a blueprint for a data type. A class definition starts with the keyword class followed by the class name.StructA structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating ... Read More

C# Numeric Promotion for Conditional Expression

Samual Sam

Samual Sam

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

91 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

806 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

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

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

738 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

Advertisements