Samual Sam has Published 2310 Articles

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

Samual Sam

Samual Sam

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

679 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 to compare two arrays in C#?

Samual Sam

Samual Sam

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

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

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

Samual Sam

Samual Sam

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

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

What is a static constructor in C#?

Samual Sam

Samual Sam

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

488 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

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

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

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

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

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

Advertisements