Karthikeya Boyini has Published 2383 Articles

How to declare member function in C# interface?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 10:22:19

149 Views

To declare member functions in interfaces in C# −public interface InterfaceName {    // interface members    void InterfaceMemberOne();    double InterfaceMembeTwo();    void InterfaceMemberThree() } public class ClassName: InterfaceName {    void InterfaceMemberOne() {       // interface member    } }Above we saw our interface members ... Read More

What are the custom exceptions in C#?

karthikeya Boyini

karthikeya Boyini

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

544 Views

Like any other programming language, in C#, you can easily create a user-defined exception. User-defined exception classes are derived from the Exception class. Custom exceptions are what we call user-defined exceptions.In the below example, the exception created is not a built-in exception; it is a custom exception −TempIsZeroExceptionYou can try ... Read More

What are destructors in C# programs?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 10:17:43

2K+ Views

A destructor is a special member function of a class that is executed whenever an object of its class goes out of scope.It has exactly the same name as that of the class with a prefixed tilde (~), for example, our class name is Demo.public Demo() { // constructor   ... Read More

Interfaces and Inheritance in C#

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 10:11:42

1K+ Views

InterfaceAn interface is defined as a syntactical contract that all the classes inheriting the interface should follow. The interface defines the 'what' part of the syntactical contract and the deriving classes define the 'how' part of the syntactical contract.Let us see an example of Interfaces in C#.Example Live Demousing System.Collections.Generic; using ... Read More

How to use the sleep method in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 10:08:15

698 Views

The sleep method of the thread is used to pause the thread for a specific period.If you want to set sleep for some seconds, then use it like the following code snippet −int sleepfor = 2000; Thread.Sleep(sleepfor);You can try to run the following code to implement the sleep method of ... Read More

How do you loop through a C# array?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 10:03:49

5K+ Views

To loop through an array in C#, use any of the loops. These loops have starting and ending value set that allows you to set or check value through iterations.C# has while, do…while, for and foreach loops to loop through an array.Let us see an example of for loop in ... Read More

Write a C# program to calculate a factorial using recursion

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 09:58:04

2K+ Views

Factorial of a number is what we are finding using a recursive function checkFact () in the below example −If the value is 1, it returns 1 since Factorial is 1 −if (n == 1) return 1;If not, then the recursive function will be called for the following iterations if ... Read More

How to use ‘is’ operator in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 09:56:17

110 Views

The "is" operator in C# checks whether the run-time type of an object is compatible with a given type or not.The following is the syntax −expr is typeHere, expr is the expression and type is the name of the typeThe following is an example showing the usage of is operator ... Read More

Class in C#

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 09:45:26

124 Views

Blueprint for a data type is what you can call a class in C#. Objects are instances of a class. The methods and variables that constitute a class are called members of the class.ExampleThe following is the general form of a class in C# − class class_name {    // ... Read More

Clone() method in C#

karthikeya Boyini

karthikeya Boyini

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

597 Views

The Clone() method in C# is used to create a similar copy of the array.Let us see an example to clone an array using the Clone() method −Example Live Demousing System; class Program {    static void Main() {       string[] arr = { "one", "two", "three", "four", "five" ... Read More

Advertisements