Created
June 3, 2015 14:24
-
-
Save gopigujjula/1550c9eed8f0a61dc099 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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