
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the interfaces implemented by Array class in C#?
System.Array implements interfaces, like ICloneable, IList, ICollection, and IEnumerable, etc. The ICloneable interface creates a copy of the existing object i.e a clone.
Let us see learn about the ICloneable interface. It only has a Clone() methods because it creates a new object that is a copy of the current instance.
The following is an example showing how to perform cloning using ICloneable interface −
Example
using System; class Car : ICloneable { int width; public Car(int width) { this.width = width; } public object Clone() { return new Car(this.width); } public override string ToString() { return string.Format("Width of car = {0}",this.width); } } class Program { static void Main() { Car carOne = new Car(1695); Car carTwo = carOne.Clone() as Car; Console.WriteLine("{0}mm", carOne); Console.WriteLine("{0}mm", carTwo); } }
Let us now see how to use Array.Clone in C# to clone an array −
Example
using System; class Program { static void Main() { string[] arr = { "one", "two", "three", "four", "five" }; string[] arrCloned = arr.Clone() as string[]; Console.WriteLine(string.Join(",", arr)); // cloned array Console.WriteLine(string.Join(",", arrCloned)); Console.WriteLine(); } }
- Related Questions & Answers
- Get all the interfaces implemented or inherited by the current Type in C#
- What are the User friendly interfaces provided by DBMS?
- What are the properties of array class in C#?
- How multiple inheritance is implemented using interfaces in Java?
- What are the data mining interfaces?
- What are the SAM Interfaces in Java?
- How are virtual functions implemented in C++?
- What are nested interfaces in Java?
- What are the in-built functional interfaces in Java?
- What are the main classes and interfaces of JDBC?
- What are some of the commonly used methods of the array class in C#?
- What do you mean by interfaces and services?
- What are class instances in C#?
- List the Interfaces That a Class Implements in Java
- Get a specific interface implemented or inherited by the current Type in C#
Advertisements