本文整理汇总了C#中SortedList.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.AddRange方法的具体用法?C# SortedList.AddRange怎么用?C# SortedList.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedList
的用法示例。
在下文中一共展示了SortedList.AddRange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Reply
/// <summary>
/// 回复信息
/// </summary>
/// <returns></returns>
public string Reply()
{
//回复信息
var result = Value;
//如果是带有记忆的*号标识
if (Star != null)
{
//如果名字不为空
if (SetVariable.Name != "" || SetVariable.Name != null)
{
//遍历每一个*符号
for (int i = 0; i < Star.Count; i++)
{
//存储变量数目
User.StoreNum++;
//设定记忆变量
Memory.Set(User.UserId + "" + User.StoreNum, SetVariable.Name, AI.Star.List[i]);
//break;
}
//返回值
//return this.Value;
}
//输出信息
//return this.Value + Smart.Star.List[Star-1];
//遍历每一个*符号
//for (int i = 0; i < this.Star.Count; i++)
//{
// result += Smart.Star.List[i];
//}
}
//如果有动态执行函数功能
if (Function != null)
{
//需要传递的参数集合
var parm = new SortedList<string>();
//将里面的索引值取出来
var star = Star;
if (star != null)
{
int[] va = star.ToArray();
//将真实值取出来
parm.AddRange(va.Select(a => AI.Star.List[a - 1]));
}
//执行,依然要把参数传递过去
return CodeCompiler.Execute(Function.Name, parm.ToArray());
}
//获取存储的变量值
if (GetVariable.Name != null)
{
//获取变量
result
+= Memory.Get(User.UserId + "" + User.StoreNum, GetVariable.Name);
}
//如果输出用户曾经的输出
if (Input != -1)
{
//输出信息
result += AI.Input.List[Input - 1];
}
if (String.IsNullOrEmpty(result))
{
//随机数的方式返回
var rnd = new Random();
//返回
if (Rand != null) return Rand.List[rnd.Next(0, Rand.List.Count)];
}
return result;
}
示例2: BuildRealCategory
//<pattern>*[地名:北京|上海|天津|-ns]*将*[行为:开盘|发布会]*</pattern>
// <template>
// <function name="Normal" para="1,2,3"></function>
// <question>[0]什么地方[1]将[2][行为][3]?[地名]</question>
// </template>
private void BuildRealCategory()
{
for (int i = 0; i < Categorys.Count; i++)
{
SortedList<Pattern> realPatterns = new SortedList<Pattern>();
SortedList<Pattern> patterns = Categorys[i].Patterns;
foreach (Pattern t in patterns)
{
if (t.Value.Contains("["))
{
string patternValue = t.Value;
List<Pattern> myPatterns = new List<Pattern>();
int leftIndex = patternValue.IndexOf('[');
int rightIndex = patternValue.IndexOf(']');
// string middleValue = string.Empty;
while (leftIndex > -1)
{
string patternString = patternValue.Substring(leftIndex + 1, rightIndex - leftIndex - 1);
string[] valueTemplate = patternString.Split(new[] { '|', ':' }, StringSplitOptions.RemoveEmptyEntries);
if (myPatterns.Count == 0)
{
Pattern[] pts = new Pattern[valueTemplate.Count() - 1];
string header = patternValue.Substring(0, leftIndex);
for (int k = 0; k < pts.Count(); k++)
{
pts[k] = new Pattern();
pts[k].Value = header + valueTemplate[k + 1];
Template template = new Template();
Template.Question[] questions =
new Template.Question[t.Template.Questions.Count];
for (int n = 0; n < questions.Count(); n++)
{
//questions[n] = new Template.Question();
//questions[n].Answer =
// t.Template.Questions[n].Answer.Replace(
// "[" + valueTemplate[0] + "]", valueTemplate[k + 1]);
//questions[n].Description = t.Template.Questions[n].Description.Replace(
// "[" + valueTemplate[0] + "]", valueTemplate[k + 1]);
}
template.Questions.AddRange(questions);
template.Function = t.Template.Function;
template.Star = t.Template.Star;
pts[k].Template = template;
}
myPatterns.AddRange(pts);
}
else
{
Pattern[,] pts = new Pattern[myPatterns.Count, valueTemplate.Count() - 1];
for (int k = 0; k < myPatterns.Count; k++)
{
for (int n = 0; n < valueTemplate.Count() - 1; n++)
{
pts[k, n] = new Pattern();
pts[k, n].Value = myPatterns[k].Value + patternValue.Substring(0, leftIndex) + valueTemplate[n + 1];
List<Template.Question> questions = myPatterns[k].Template.Questions;
Template template = new Template();
for (int m = 0; m < questions.Count; m++)
{
//Template.Question myQuestion = new Template.Question();
//myQuestion.Description = questions[m].Description.Replace(
// "[" + valueTemplate[0] + "]", valueTemplate[n + 1]);
//myQuestion.Answer = questions[m].Answer.Replace(
// "[" + valueTemplate[0] + "]", valueTemplate[n + 1]);
//template.AddQuestion(myQuestion);
}
template.Function = myPatterns[k].Template.Function;
template.Star = myPatterns[k].Template.Star;
pts[k, n].Template = template;
}
}
myPatterns.Clear();
foreach (var p in pts)
{
myPatterns.Add(p);
}
}
patternValue = patternValue.Substring(rightIndex + 1, patternValue.Length - rightIndex - 1);
// int lastRightIndex = rightIndex;
leftIndex = patternValue.IndexOf('[');
rightIndex = patternValue.IndexOf(']');
if (rightIndex == -1)
{
foreach (Pattern t1 in myPatterns)
{
t1.Value += patternValue;
}
}
//.........这里部分代码省略.........