using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace interfacesdemo
{
interface payroll //don't put security on it
{//pre-defines names
void print_t4();
double taxit(double x);
}
class emp : payroll
{ public void print_t4()
{ Console.WriteLine("my code");
}
public double taxit(double x)
{ return x * 0.3;
}
}
class worker:ICloneable,IDisposable
{ public string name;
public double salary;
public void Copy(worker w)
{ this.name = w.name; //multi-variable copy
this.salary = w.salary;
}
public object Clone()
{ return this.MemberwiseClone();//single line copy all variables
}
public void Dispose()//like a destructor for memory
{//remove line of code it makes
}
}
class mylist : IList<worker> //allows you to make your own lists
{
public int IndexOf(worker item)
{
throw new NotImplementedException();
}
public void Insert(int index, worker item)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
throw new NotImplementedException();
}
public worker this[int index]
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public void Add(worker item)
{
throw new NotImplementedException();
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(worker item)
{
throw new NotImplementedException();
}
public void CopyTo(worker[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public int Count
{
get { throw new NotImplementedException(); }
}
public bool IsReadOnly
{
get { throw new NotImplementedException(); }
}
public bool Remove(worker item)
{
throw new NotImplementedException();
}
public IEnumerator<worker> GetEnumerator()
{
throw new NotImplementedException();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
class Program
{ static void Main(string[] args)
{
using(worker wx=new worker())
{
wx.name="ed";
}//memory is thrown away immediately
worker w1 = new worker();
w1.name = "bob";
w1.salary = 80000;
worker w2 = new worker();
w2 = (worker)w1.Clone();//like a copy
w2.Copy(w1);
//memory control
w1 = null; //eventually remove memory
{
worker w3 = new worker();
w3.name = "ed";
} //at end of brackets, memory eventually goes away
System.GC.Collect(); //do this if brackets or null used
//collect removes memory immediately
//payroll p = new payroll(); cannot use directly
}
}
}
Tuesday, 29 March 2016
c# interface
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment