Is it possible to define a member function which have the return type same as the class where it is a member.
eg:
public class Cars
{
int Model
int Make
Cars CreateDeepCopy()
{
using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, this);
ms.Position = 0;
return (Cars)formatter.Deserialize(ms);
}
}
}
Sure, just make sure you polish the syntax to make it valid C# in order to compile and that you decorate your class with the
[Serializable]attribute or you won’t be able to use a BinaryFormatter to serialize it: