# Twig<T> class

Namespace: [Grasshopper2.Data](https://developer.rhino3d.com/api/gh2/namespace/grasshopper2.data.md) · Assembly: [Grasshopper2](https://developer.rhino3d.com/api/gh2/assembly/grasshopper2.md)

```cs
public abstract class Twig<T> : ITwig
```

Type constrained re-implemention of ITwig.

**Type parameters:**

- `T`: Type of data in twig.

## Properties

- [CommonMetaData](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/commonmetadata.md): Gets the common meta data in this twig. This means the meta data shared amongst all non-null items. Any conflicting meta data (i.e. identical name, different values) will be omitted from this result.
- [Constraint](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/constraint.md): Gets the type constraint for this twig. Since each [ITwig](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.itwig.md) instance is some form of [Twig<T>](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1.md), this property tells you what T is.
- [Flavour](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/flavour.md): Gets the type flavour of the T constraint.
- [ITwig.Items](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-items.md)
- [ITwig.NonNullItems](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-nonnullitems.md)
- [ITwig.NonNullPears](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-nonnullpears.md)
- [ITwig.Pears](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-pears.md)
- [ItemCount](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/itemcount.md): Gets the number of items in this twig that aren't considered null.
- [Items](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/items.md): Get an enumerator for all items in this twig.
- [LeafCount](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/leafcount.md): Gets the number of items in this twig, including nulls.
- [MetaCount](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/metacount.md): Gets the number of defined meta data palettes in this twig.
- [NonNullItems](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/nonnullitems.md): Get an enumerator for all non-null items in this twig.
- [NonNullPears](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/nonnullpears.md): Enumerate over all non-null item/meta data tuples.
- [NullCount](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/nullcount.md): Gets the number of items in this twig that are nulls. Note: even when a twig contains ValueTypes, it may still have nulls.
- [Pears](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/pears.md): Enumerate over all item/meta data tuples.
- [TightConstraint](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/tightconstraint.md): Gets the type which is common to all values stored in this twig. This is potentially quite an expensive property to call and its value is not cached internally. If the twig contains no values at all, the return value is somewhat undefined but will either be [object](https://learn.microsoft.com/dotnet/api/system.object) or [ITwig.Constraint](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.itwig/constraint.md).

## Indexers

- [ITwig.this[]](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-this.md)
- [this[]](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/item.md): Gets the item/data pear at the given index.

## Methods

- [Add](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/add.md): (3 overloads) Add an item/data pear to this twig.
- [AddNull](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/addnull.md): Add a null item to this twig.
- [AddRange](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/addrange.md): (4 overloads) Add a collection of item/data pears to this twig. This is the fastest AddRange method, especially if the pears argument is in fact an array of pears.
- [Apply](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/apply.md): (2 overloads) Apply an expression to all non-null elements in this twig. For an expression to be successful it needs to not throw exceptions and have a return type that is compatible with the underlying type of this twig.
- [Cast](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/cast.md): (2 overloads) Cast this twig to a [Twig<T>](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1.md) type. This will only work if all non-null items are of the given type.
- [ClearMetaData](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/clearmetadata.md): Create a new twig with the same items but with no meta data.
- [Convert<TQ>](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/convert.md): (3 overloads) Convert this twig into another twig of a different type.
- [CountItems](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/countitems.md): Count how many items pass a predicate method. Null items are not tested and do not contribute towards the test.
- [CountPears](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/countpears.md): Count how many item/data pears pass a predicate method. Null items will be included as pears.NullAt = true;
- [Expand](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/expand.md): Expand this twig until the count is equal to the target count. This functionality is the basis for LongestList matching.
- [Format](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/format.md): (5 overloads) Format this twig.
- [ITwig.Apply](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-apply.md)
- [ITwig.ClearMetaData](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-clearmetadata.md)
- [ITwig.Expand](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-expand.md)
- [ITwig.Format](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-format.md): (2 overloads)
- [ITwig.ItemAt](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-itemat.md)
- [ITwig.Map](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-map.md)
- [ITwig.MergeMetaData](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-mergemetadata.md): (2 overloads)
- [ITwig.RemoveAll](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-removeall.md): (2 overloads)
- [ITwig.RemoveAt](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-removeat.md)
- [ITwig.RemoveIndices](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-removeindices.md)
- [ITwig.RemoveMetaData](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-removemetadata.md)
- [ITwig.RemoveNulls](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-removenulls.md)
- [ITwig.RemovePattern](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-removepattern.md)
- [ITwig.RemoveRange](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-removerange.md)
- [ITwig.Reverse](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-reverse.md)
- [ITwig.Shrink](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-shrink.md)
- [ITwig.Sort](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-sort.md): (4 overloads)
- [ITwig.ToPearArray](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/grasshopper2-data-itwig-topeararray.md)
- [Insert](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/insert.md): (3 overloads) Insert an item/data pear into this twig.
- [InsertNull](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/insertnull.md): Insert a null item into this twig.
- [InsertRange](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/insertrange.md): (4 overloads) Insert a collection of item/data pears into this twig.
- [ItemAt](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/itemat.md): Gets the item at the given index.
- [Map](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/map.md): Internal sort method based on an index map.
- [MergeMetaData](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/mergemetadata.md): (2 overloads) Merge all meta data from another twig.
- [MetaAt](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/metaat.md): Gets the meta data at the given index.
- [NullAt](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/nullat.md): Gets whether the item at the given index is considered to be a null value.
- [RemoveAll](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/removeall.md): (2 overloads) Remove all item/data pears that pass a predicate method.
- [RemoveAt](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/removeat.md): Remove the item at the given index.
- [RemoveIndices](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/removeindices.md): Remove all indices from this twig.
- [RemoveMetaData](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/removemetadata.md): Remove all meta values with the given names from this twig.
- [RemoveNulls](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/removenulls.md): Remove all null items from this twig.
- [RemovePattern](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/removepattern.md): Remove all items that are represented by a boolean pattern.
- [RemoveRange](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/removerange.md): Remove a range of items.
- [Reverse](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/reverse.md): Reverse the order of all items in this twig.
- [Shrink](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/shrink.md): Shrink this twig until the count is equal to the target count. This functionality is the basis for ShortestList matching.
- [Sort](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/sort.md): (6 overloads) Sort all items using a key array of doubles.
- [ToItemArray](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/toitemarray.md): Copy the items to an array.
- [ToItemArrayInternal](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/toitemarrayinternal.md): Return a direct reference to the internal item array if it exists.
- [ToMetaArray](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/tometaarray.md): Copy the meta data (if any) to an array.
- [ToMetaArrayInternal](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/tometaarrayinternal.md): Return a direct reference to the internal meta data array if it exists.
- [ToNullArray](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/tonullarray.md): Copy the null data (if any) to an array. This method may return null if there is no null data.
- [ToNullArrayInternal](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/tonullarrayinternal.md): Return a direct reference to the internal null flag array if it exists.
- [ToPearArray](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/topeararray.md): Create an array of item/data pears.
- [TrueForItems](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/trueforitems.md): Test whether a specific predicate is true for all items in this twig. Null items are not tested and do not contribute towards the test.
- [TrueForPears](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/trueforpears.md): Test whether a specific predicate is true for all item/data pears in this twig.
- [TryConvert<TQ>](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/tryconvert.md): (2 overloads) Try and convert this twig into another using the set of centrally registered conversion delegates.
- [TypeAt](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/typeat.md): Gets the type of the item at the given index.
- [TypeName](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/typename.md): (2 overloads) Gets the user friendly type name of the twig type constraint.
- [ValidateIndex](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/validateindex.md): (2 overloads) Throw an exception if the index + length range exceed the twig size.
- [ValidateIndexPlusOne](https://developer.rhino3d.com/api/gh2/type/grasshopper2.data.twig-1/validateindexplusone.md): (2 overloads) Throw an exception if the index + length range exceed the twig size plus one.
