Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace UsingTest
{
public class Program
{
static void Main(string[] args)
{
//Compiler error - "type used in a using statement must be implicitly convertible to 'System.IDisposable'".
using (Customer objCustomer = new Customer("Kevin"))
{
Console.WriteLine(objCustomer.ToString());
Console.ReadKey();
}
using (Student objStudent = new Student("Kevin"))
{
Console.WriteLine(objStudent.ToString());
Console.ReadKey();
}
}
}
public class Customer
{
public string Name { get; set; }
public Customer(string name)
{
this.Name = name;
}
public override string ToString()
{
return Name;
}
}
public class Student :IDisposable
{
public string Name { get; set; }
public Student(string name)
{
this.Name = name;
}
public override string ToString()
{
return Name;
}
void Dispose()
{
throw new NotImplementedException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment