# Using Sequences in C#

The C# Sequence class is used to manage database fields of type sequence. As sequences are effectively vectors of values, they are accessed through iterators. Where the C type `mco_seq_iterator_h` is used in C applications, the C# class Sequence serves the equivalent role in C# applications. The Sequence class also provides a powerful set of Analytics Methods for performing mathematical and statistical operations on sequences.

## Inserting and Updating Sequences in C#

> Normally sequence data is inserted using the C# Sequence method `Append()`. For example consider the following schema definition:

>         [Persistent]
>         public class Quote {
>             [Indexable(Unique=true)]
>             [Dimensiohn(21)]
>             public String           symbol;

>             [Sequence(Order=SequenceOrder.Ascending)]
>             public OrderedSequence<uint> Day;

>             [Sequence()]
>             UnorderedSequence<float> Price;
>         };

> With this class definition, the Quote sequence fields `Day` and `Price` can be populated with code like the following:

>         con.StartTransaction(Database.TransactionType.ReadWrite);
>         Quote q = new Quote();
>         q.symbol_= "IBM";
>         con.Insert(q);
>         q.Day.Append(new uint[] { 1, 2, 4, 5 });
>         q.Price.Append(new float[] { 10, 20, 40, 50 });
>         con.CommitTransaction();

> It may sometimes be necessary to insert values into an ordered time series. Values can be inserted into an existing sequence using the Sequence method `Insert()`. For example, the following code snippet searches for the Quote object with symbol "`IBM`", then inserts `Day` and `Price` values:

>         con.StartTransaction(Database.TransactionType.ReadWrite);
>         Cursor<Quote> cursor = new Cursor<Quote>(con, "symbol");
>         Quote q = cursor.Find("IBM");
>         Sequence seq = q.Day.Search(3, SelectBoundary.Exclusive, 0, SelectBoundary.Open);
>         ulong pos = seq.FirstPosition;
>         q.Day.Insert(pos, new uint[] { 3u });
>         q.Price.Insert(pos, new float[] { 30 });
>         con.CommitTransaction();