C#
C# Collections Tutorial with Examples
In our previous tutorial, we have learned about how we can use arrays in C#. Let's have a quick...
Interfaces are used along with classes to define what is known as a contract. A contract is an agreement on what the class will provide to an application.
An interface declares the properties and methods. It is up to the class to define exactly what the method will do.
Let's look at an example of an interface by changing the classes in our Console application. Note that we will not be running the code because there is nothing that can be run using an interface.
Let's create an interface class. The class will be called "gtupapersInterface." Our main class will then extend the defined interface. All the code needs to be written in the Program.cs file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
interface gtupapersInterface
{
void SetTutorial(int pID, string pName);
String GetTutorial();
}
class gtupapersTutorial : gtupapersInterface
{
protected int TutorialID;
protected string TutorialName;
public void SetTutorial(int pID, string pName)
{
TutorialID = pID;
TutorialName = pName;
}
public String GetTutorial()
{
return TutorialName;
}
static void Main(string[] args)
{
gtupapersTutorial pTutor = new gtupapersTutorial();
pTutor.SetTutorial(1,".Net by gtupapers");
Console.WriteLine(pTutor.GetTutorial());
Console.ReadKey();
}
}
}Code Explanation:-
Here, we explain the important sections of the code
Summary
In our previous tutorial, we have learned about how we can use arrays in C#. Let's have a quick...
What is .Net Framework? .Net Framework is a software development platform developed by Microsoft for...
In this tutorial, you will learn- Inheritance Polymorphism What is Inheritance in C#? Inheritance is...
In this tutorial, you will learn- Access Modifiers Constructor Access Modifiers Access Modifiers or...
In C# file operations, normally streams are used to read and write to files. A stream is an...
Accessing Data from a database is one of the important aspects of any programming language. It is...