Samual Sam has Published 2310 Articles

How to declare and initialize a list in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 10:28:04

14K+ Views

To declare and initialize a list in C#, firstly declare the list −List myList = new List()Now add elements −List myList = new List() {    "one",    "two",    "three", };Through this, we added six elements above.The following is the complete code to declare and initialize a list in ... Read More

How to declare and instantiate Delegates in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 10:26:30

424 Views

C# delegates are similar to pointers to functions, in C or C++. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.Syntax for declaring Delegates −delegate Let us now see how to instantiate delegates in C#.Once a ... Read More

How to declare and use Interfaces in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 10:24:46

219 Views

Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members.Let us declare interfaces −public interface ITransactions {    // interface members    void showTransaction();    double getAmount(); ... Read More

What are delegates in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 10:21:40

338 Views

A delegate in C# is a reference to the method. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegate class.Let ... Read More

What are different methods of passing parameters in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 10:16:10

394 Views

When a method with parameters is called, you need to pass the parameters to the method using any of the following three methods -Reference ParametersThis method copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the ... Read More

How to declare an empty string array in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 10:12:28

3K+ Views

In C#, you can use strings as an array of characters, However, more common practice is to use the string keyword to declare a string variable. The string keyword is an alias for the System.String class.To declare an empty string.string[] arr = new string[] {}; // empty stringNow let us ... Read More

Write a C# program to check if a number is prime or not

Samual Sam

Samual Sam

Updated on 20-Jun-2020 10:09:09

4K+ Views

To calculate whether a number is prime or not, we have used a loop and within that on every iteration, we have an if statement to find that the remainder is equal to 0, between the number itself.for (int i = 1; i

How to use RightShift Operators in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 10:07:26

154 Views

The left operands value is moved right by the number of bits specified by the right operand in Right Shift Operator.Let us see an example of Right Shift operator in C# −using System; namespace OperatorsAppl {    class Program {       static void Main(string[] args) ... Read More

How to concatenate Two Arrays in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 10:02:38

523 Views

To concatenate two arrays in C#, let us first declare and initialize the array. Here, we have considered a string array −string[] str = new string[] { "Hello", "World" };Now let us use the join() method to concatenate −.string.Join(" ", str);Now let us see the complete code to concatenate two ... Read More

What are control statements in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 09:59:29

6K+ Views

The flow of program control is specified by control statements in C#. It includes the following −if statementAn if statement consists of a boolean expression followed by one or more statements.The following is the syntax −if(boolean_expression) {    /* statement(s) will execute if the boolean expression is true */ }if-else ... Read More

Advertisements