Tag Archives: OOP

Determine whether two lists contain the same sequences of objects in different orders in C#

The SequenceEqual method determines whether two IEnumerable sequences contain the same objects in the same order. There is a simple way to determine whether the lists contain the same objects in different orders: sort the objects and then call SequenceEqual. … Continue reading

Posted in LINQ, lists, miscellany, OOP | Tagged , , , , , , , , , , , , , | Leave a comment

Determine whether two lists contain the same sequences of objects in C#

The IEnumerable interface provides a SequenceEqual method that determines whether two IEnumerable sequences contain the same objects. Normally, it uses reference equality so it considers two objects equal only if they refer to the same instance. However, if the objects … Continue reading

Posted in lists, miscellany, OOP | Tagged , , , , , , , , , , , | 2 Comments

Draw a scrolling family tree in C#

The example Draw a family tree in C# shows how to draw a family tree. Unfortunately if the tree is too big, you can’t make the form big enough to display it all. One solution would be to use smaller … Continue reading

Posted in algorithms, classes, generic, graphics, OOP | Tagged , , , , , , , , , , , , , , , , , , , , , | 1 Comment

Clone lists and arrays of objects in C#

This is the last post I’ll write about clones, at least for a while. Some collection classes can already make clones. For example, an array can clone itself, although the result is always a shallow clone. This example shows how … Continue reading

Posted in algorithms, OOP, syntax | Tagged , , , , , , , , , , , , , | 1 Comment

Clone serializable objects in C#

If a class is serializable, then you can create a deep clone of an object from that class by serializing it and the deserializing it. This example uses the following code to define a generic extension method that clones objects … Continue reading

Posted in algorithms, OOP, syntax | Tagged , , , , , , , , , , , , , | 5 Comments

Use MemberwiseClone the ICloneable interface in C#

The example Clone objects in C# explains how to give a class a Clone method that makes copies of its objects. This example makes two changes: it implements the ICloneable interface and it uses MemberwiseClone to simplify the cloning code. … Continue reading

Posted in algorithms, OOP, syntax | Tagged , , , , , , , , , , , , , , , | Leave a comment

Clone objects in C#

A clone of an object is a copy of that object. There are two kinds of clones: shallow and deep. A shallow clone shares all of the same values as the original object, even if some of those values are … Continue reading

Posted in algorithms, OOP, syntax | Tagged , , , , , , , , , , , , | Leave a comment

Provide multiple inheritance in C#

Sometimes you might want a class to inherit from more than one parent class. For example, you might define a Vehicle class that has vehicle properties such as MaxSpeed, and a Domicile class with house-like properties such as SquareFeet. You … Continue reading

Posted in inheritance, interfaces, OOP | Tagged , , , , , , , , , | 1 Comment

Define and implement an interface in C#

(This example doesn’t do anything. It just shows how to define an interface.) An interface defines properties, methods, and events for a class but doesn’t provide an implementation for them. A class that implements the interface must provide code for … Continue reading

Posted in interfaces, OOP | Tagged , , , , , , , , , | Leave a comment

Override a parent class method in C#

One of the coolest features of object-oriented programming is virtual methods. If a parent class declares a method as virtual, a child class can provide a new implementation for the method. When the program calls the method for a child … Continue reading

Posted in classes, OOP | Tagged , , , , , , , , , , , , | 1 Comment