本文整理汇总了C#中VList.Transform方法的典型用法代码示例。如果您正苦于以下问题:C# VList.Transform方法的具体用法?C# VList.Transform怎么用?C# VList.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VList
的用法示例。
在下文中一共展示了VList.Transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestExampleTransforms
public void TestExampleTransforms()
{
// These examples are listed in the documentation of FVList.Transform().
// There are more Transform() tests in VListTests() and RWListTests().
VList<int> list = new VList<int>(new int[] { -1, 2, -2, 13, 5, 8, 9 });
VList<int> output;
output = list.Transform((int i, ref int n) =>
{ // Keep every second item
return (i % 2) == 1 ? XfAction.Keep : XfAction.Drop;
});
ExpectList(output, 2, 13, 8);
output = list.Transform((int i, ref int n) =>
{ // Keep odd numbers
return (n % 2) != 0 ? XfAction.Keep : XfAction.Drop;
});
ExpectList(output, -1, 13, 5, 9);
output = list.Transform((int i, ref int n) =>
{ // Keep and square all odd numbers
if ((n % 2) != 0) {
n *= n;
return XfAction.Change;
} else
return XfAction.Drop;
});
ExpectList(output, 1, 169, 25, 81);
output = list.Transform((int i, ref int n) =>
{ // Increase each item by its index
n += i;
return i == 0 ? XfAction.Keep : XfAction.Change;
});
ExpectList(output, -1, 3, 0, 16, 9, 13, 15);
list = new VList<int>(new int[] { 1, 2, 3 });
output = list.Transform(delegate(int i, ref int n) {
return i >= 0 ? XfAction.Repeat : XfAction.Keep;
});
ExpectList(output, 1, 1, 2, 2, 3, 3);
output = list.Transform(delegate(int i, ref int n) {
if (i >= 0)
return XfAction.Repeat;
n *= 10;
return XfAction.Change;
});
ExpectList(output, 1, 10, 2, 20, 3, 30);
output = list.Transform(delegate (int i, ref int n) {
if (i >= 0) {
n *= 10;
return XfAction.Repeat;
}
return XfAction.Keep;
});
ExpectList(output, 10, 1, 20, 2, 30, 3);
output = list.Transform(delegate (int i, ref int n) {
n *= 10;
if (n > 1000)
return XfAction.Drop;
return XfAction.Repeat;
});
ExpectList(output, 10, 100, 1000, 20, 200, 30, 300);
}