38. Simple Interface in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace simple_interface.cs
{
interface product
{
int pid {get; set;}
string pname {get; set;}
double price {get; set;}
double pqty(double qty);
}
class siminterface : product
{
int no;
double cost;
string nm;
public int pid
{
get { return no; }
set { no = value; }
}
public string pname
{
get { return nm; }
set { nm = value; }
}
public double price
{
get { return cost; }
set { cost = value; }
}
public double pqty(double qty)
{
Console.WriteLine("Product Quantity : " + qty);
return price * qty;
}
}
class Program
{
static void Main(string[] args)
{
siminterface obj = new siminterface();
obj.pid = 1;
obj.pname ="Mobile";
obj.price = 2000;
Console.WriteLine("Product ID : " + obj.pid);
Console.WriteLine("Product Name : " + obj.pname);
Console.WriteLine("Product Price : " + obj.price);
Console.WriteLine("Total Cost : " + obj.pqty(2));
Console.Read();
}
}
}
OUTPUT:
Product ID : 1
Product Name : Mobile
Product Price : 2000
Product Quantity : 2
Total Cost : 4000
Comments
Post a Comment