Demonstrate ICloneable : Clone « Language Basics « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Language Basics » CloneScreenshots 
Demonstrate ICloneable
Demonstrate ICloneable

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/

// Demonstrate ICloneable. 
 
using System;  
 
class 
  public int a; 
 
  public X(int x) { a = x; 

 
class Test : ICloneable 
  public X o; 
  public int b; 
 
  public Test(int x, int y) { 
    o = new X(x)
    b = y; 
  
 
  public void show(string name) { 
    Console.Write(name + " values are ")
    Console.WriteLine("o.a: {0}, b: {1}", o.a, b)
  
 
  // Make a deep copy of the invoking object. 
  public object Clone() { 
    Test temp = new Test(o.a, b)
    return temp; 
  
     

  
public class CloneDemo {     
  public static void Main() {     
    Test ob1 = new Test(1020)
 
    ob1.show("ob1")
 
    Console.WriteLine("Make ob2 a clone of ob1.")
    Test ob2 = (Testob1.Clone()
 
    ob2.show("ob2")
 
    Console.WriteLine("Changing ob1.o.a to 99 and ob1.b to 88.")
    ob1.o.a = 99
    ob1.b = 88
 
    ob1.show("ob1")
    ob2.show("ob2")
  
}


           
       
Related examples in the same category
1. Copy a classCopy a class
2. System.Array and the Collection Classes:ICloneable 1System.Array and the Collection Classes:ICloneable 1
3. System.Array and the Collection Classes:ICloneable 2System.Array and the Collection Classes:ICloneable 2
ww__w___.___j_a___v__a_2s___.___co_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.