I want to clone an object using the ICloneable interface and for some reason I cannot clone in my program. Here is my code:
public class GeoInfo : ICloneable { private long InfoID; private string InfoName; private Location InfoLocation; private string Description; private InfoTypes InfoType; public GeoInfo(long InfoID) { this.InfoID = InfoID; } public GeoInfo(long InfoID, Location InfoLocation):this(InfoID) { this.InfoLocation = InfoLocation; } public GeoInfo(long InfoID, string InfoName, Location InfoLocation, string Description, InfoTypes InfoType):this(InfoID,InfoLocation) { this.InfoName = InfoName; this.Description = Description; this.InfoType = InfoType; } public object ICloneable.Clone() { GeoInfo toReturn = new GeoInfo(InfoID, InfoName, InfoLocation, Description, InfoType); return (object)toReturn; }
}
Inside another class, when I try to use the Clone() method, for some reason, the compiler cannot find the method. Here is my other method that is trying to clone:
public InfoLayer(string LayerName,List<GeoInfo> oldGeoInfos) { this.LayerName = LayerName; this.GeoInfos = new List<GeoInfo>(); oldGeoInfos.ForEach((item) => { GeoInfos.Add((GeoInfo)((ICloneable)item.Clone())); }); }
source share