本文整理汇总了C#中Sequence.Length方法的典型用法代码示例。如果您正苦于以下问题:C# Sequence.Length方法的具体用法?C# Sequence.Length怎么用?C# Sequence.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sequence
的用法示例。
在下文中一共展示了Sequence.Length方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Concat
/**
* Creates a new token sequence that is the concatenation
* of this sequence and another. A maximum length for the
* new sequence is also specified.
*
* @param length the maximum length of the result
* @param seq the other sequence
*
* @return the concatenated token sequence
*/
public Sequence Concat(int length, Sequence seq) {
Sequence res = new Sequence(length, this);
if (seq.repeat) {
res.repeat = true;
}
length -= this.Length();
if (length > seq.Length()) {
res.tokens.AddRange(seq.tokens);
} else {
for (int i = 0; i < length; i++) {
res.tokens.Add(seq.tokens[i]);
}
}
return res;
}
示例2: Sequence
/**
* Creates a new token sequence that is a duplicate of
* another sequence. Only a limited number of tokens will
* be copied however. The repeat flag from the original
* will be kept intact.
*
* @param length the maximum number of tokens to copy
* @param seq the sequence to copy
*/
public Sequence(int length, Sequence seq) {
this.repeat = seq.repeat;
this.tokens = new ArrayList(length);
if (seq.Length() < length) {
length = seq.Length();
}
for (int i = 0; i < length; i++) {
tokens.Add(seq.tokens[i]);
}
}
示例3: StartsWith
/**
* Checks if this token sequence starts with the tokens from
* another sequence. If the other sequence is longer than this
* sequence, this method will always return false.
*
* @param seq the token sequence to check
*
* @return true if this sequence starts with the other, or
* false otherwise
*/
public bool StartsWith(Sequence seq) {
if (Length() < seq.Length()) {
return false;
}
for (int i = 0; i < seq.tokens.Count; i++) {
if (!tokens[i].Equals(seq.tokens[i])) {
return false;
}
}
return true;
}
示例4: Add
/**
* Adds a token sequence to this set. The sequence will only
* be added if it is not already in the set. Also, if the
* sequence is longer than the allowed maximum, a truncated
* sequence will be added instead.
*
* @param seq the token sequence to add
*/
private void Add(Sequence seq) {
if (seq.Length() > maxLength) {
seq = new Sequence(maxLength, seq);
}
if (!Contains(seq)) {
elements.Add(seq);
}
}