Skip to content

Instantly share code, notes, and snippets.

@gopigujjula
Created June 3, 2015 14:24
Show Gist options
  • Save gopigujjula/1550c9eed8f0a61dc099 to your computer and use it in GitHub Desktop.
Save gopigujjula/1550c9eed8f0a61dc099 to your computer and use it in GitHub Desktop.
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