create a generic modal logic system class and ienumarable in csharp

Here's an example of how you can create a generic modal logic system class that implements the IEnumerable interface:

main.cs
public class ModalLogicSystem<T> : IEnumerable<T>
{
    private List<T> values;

    public ModalLogicSystem()
    {
        values = new List<T>();
    }

    public void Add(T value)
    {
        values.Add(value);
    }

    IEnumerator<T> IEnumerable<T>.GetEnumerator()
    {
        return values.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return values.GetEnumerator();
    }
}
424 chars
25 lines

This class uses a List<T> to store the values and implements the Add method to add new values to the list. It also implements the IEnumerable<T> interface and provides the GetEnumerator method to allow enumeration of the values in the list.

You can use this class like this:

main.cs
var modalLogicSystem = new ModalLogicSystem<int>();

modalLogicSystem.Add(1);
modalLogicSystem.Add(2);
modalLogicSystem.Add(3);

foreach (var value in modalLogicSystem)
{
    Console.WriteLine(value);
}
203 chars
11 lines

This will output:

main.cs
1
2
3
6 chars
4 lines

gistlibby LogSnag