Samual Sam has Published 2492 Articles

What is a static constructor in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 12:46:43

346 Views

A static constructor is a constructor declared using a static modifier. It is the first block of code executed in a class. With that, a static constructor executes only once in the life cycle of class.The following is an example of static constructors in C# −Exampleusing System; using System.Collections.Generic; using ... Read More

What is a copy constructor in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 12:39:00

3K+ Views

Copy Constructor creates an object by copying variables from another object.Let us see an example −Exampleusing System; namespace Demo {    class Student {       private string name;       private int rank;       public Student(Student s) {          name = ... Read More

Log functions in C#

Samual Sam

Samual Sam

Updated on 21-Jun-2020 12:31:31

1K+ Views

With C#, you can easily work with Logarithms. It has the following methods for Log as well as Log base 10.Sr.NoMethod & Description1Log(Double)Returns the natural (base e) logarithm of a specified number.2LogDouble)(Double, Returns the logarithm of a specified number in a specified base.3Log10(Double)Returns the base 10 logarithm of a specified ... Read More

What are tokens in C#?

Samual Sam

Samual Sam

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

2K+ Views

Token is the smallest element of a program. Let us learn about identifiers and keywords in C# that are tokens −KeywordsKeywords are reserved words predefined to the C# compiler. These keywords cannot be used as identifiers. However, if you want to use these keywords as identifiers, you may prefix the ... Read More

What is Type safe in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 12:13:47

1K+ Views

Type safe in C# wouldn’t allow an object to sneak into other object’s memory. Let us see an example to understand the concept of −Examplepublic class One {    public int Prop{ get; set;} } public class Two {    public int Prop{get;set;}    public int Prop1{get;set;} }Let’s say ... Read More

What are the interfaces implemented by Array class in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 12:05:51

804 Views

System.Array implements interfaces, like ICloneable, IList, ICollection, and IEnumerable, etc. The ICloneable interface creates a copy of the existing object i.e a clone.Let us see learn about the ICloneable interface. It only has a Clone() methods because it creates a new object that is a copy of the current instance.The ... Read More

What are static or fixed length arrays in C#?

Samual Sam

Samual Sam

Updated on 21-Jun-2020 11:56:11

1K+ Views

A static array is a data structure with a fixed size. Let us see an example of a static array in C#.Here is a static string array. The data remains the same here i.e. fixed −static string[] _fruits = new string[] {    "apple",    "mango" };Now let us see ... Read More

What is a dictionary in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 17:34:34

2K+ Views

Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.To declare and initialize a Dictionary −IDictionary d = new Dictionary();Above, types of key and value are set while declaring a dictionary object. An int is a type of key and string is a ... Read More

What is the best way to iterate over a Dictionary in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 17:32:59

1K+ Views

In a Dictionary collection, store any data type. Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.Let us now see the best way to iterate over a Dictionary in C# −Firstly, let us create a dictionary −var d = new Dictionary(5);Now add ... Read More

What are multicasting delegates in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 17:30:17

1K+ Views

A delegate that holds a reference to more than one method is called multicasting delegate.Let us see an example −Exampleusing System; delegate void myDelegate(int val1, int val2); public class Demo {    public static void CalAdd(int val1, int val2) {       Console.WriteLine("{0} + {1} = {2}", val1, val2, ... Read More

Advertisements