TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How To Define A User Defined Interface And Its Implementation In Class Using C#
Vijayaragavan S
Aug 24
2016
Code
1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System;
//Interface definition
public
interface
Shape {
void
area();
}
public
class
Circle: Shape
//implementing user defined interface
{
public
void
area() {
Console.WriteLine(
"*** Calculating Area of Circle ***"
);
Console.Write(
"Enter the Radius:"
);
float
r =
float
.Parse(Console.ReadLine());
Console.WriteLine(
"Area of Circle = "
+ (3.142 * r * r));
}
}
public
class
Square: Shape {
public
void
area() {
Console.WriteLine(
"*** Calculating Area of Square ***"
);
Console.Write(
"Enter the Length:"
);
float
side =
float
.Parse(Console.ReadLine());
Console.WriteLine(
"Area of Square = "
+ (side * side));
}
}
class
arrinterfacetest {
static
void
Main(
string
[] args) {
Console.WriteLine(
"*** Array of Interface Test ***"
);
Shape[] s =
new
Shape[2];
s[0] =
new
Circle();
s[1] =
new
Square();
for
(
int
i = 0; i < s.Length; i++) {
s[i].area();
Console.ReadKey();
}
}
}
User Defined Interface
C#