The microsoft docs show that C#'s Array.Clone() method returns type object:
object
public object Clone ();
and indeed the example they give includes a cast.
eg
int[] myClone1 = (new int[2]).Clone(); // Type error int[] myClone2 = (int[])(new int[2]).Clone(); // All good
Why does Clone() return object instead of the expected type ?
Because .Clone() returns an object not an int. Therefore it needs a cast to be of type int.
.Clone()
int
1.4m articles
1.4m replys
5 comments
56.9k users