本文整理汇总了C#中List.GetRange方法的典型用法代码示例。如果您正苦于以下问题:C# List.GetRange方法的具体用法?C# List.GetRange怎么用?C# List.GetRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.GetRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DivideAndConquer
private List<PointF> DivideAndConquer(List<PointF> points)
{
if (points.Count == 2 || points.Count == 3)
{
// TODO make sure they are in CC order starting with the left-most
return points;
}
// Find the middle index
int middleIdx = points.Count / 2;
if(points.Count % 2 == 1)
middleIdx++;
// DAC the left and right ranges of the points
List<PointF> edgePtsLeft = DivideAndConquer(points.GetRange(0, middleIdx));
List<PointF> edgePtsRight = DivideAndConquer(points.GetRange(middleIdx, points.Count - middleIdx));
// Get upper and lower tangent indexes
Tuple<int, int> upperTangentIndexes = FindUpperTangent();
Tuple<int, int> lowerTangentIndexes = FindLowerTangent();
int idxOfUpperTangentInEdgePtsL = upperTangentIndexes.Item1;
int idxOfUpperTangentInEdgePtsR = upperTangentIndexes.Item2;
int idxOfLowerTangentInEdgePtsL = lowerTangentIndexes.Item1;
int idxOfLowerTangentInEdgePtsR = lowerTangentIndexes.Item2;
// Combine the new hulls using the newly found indexes
List<PointF> combinedEdgePts = new List<PointF>();
return combinedEdgePts;
}
示例2: ReceiveUDP
private static void ReceiveUDP(IAsyncResult ar)
{
var u = (UdpClient)((UdpState)(ar.AsyncState)).u;
var e = (IPEndPoint)((UdpState)(ar.AsyncState)).e;
var rawBytes = new List<byte>();
rawBytes.AddRange(u.EndReceive(ar, ref e));
var FromAddress = rawBytes.GetRange(1, rawBytes[0]);
var receiveBytes = rawBytes.GetRange(rawBytes[0] + 1, rawBytes.Count - 1 - rawBytes[0]).ToArray();
switch ((PDUbase.MessageTypeIndicator)receiveBytes[0])
{
case PDUbase.MessageTypeIndicator.DeliverReport:
case PDUbase.MessageTypeIndicator.Command:
break;
case PDUbase.MessageTypeIndicator.Submit:
var packet = new SMS_Submit {BinaryForm = receiveBytes};
var hairpin = packet.DestinationAddress.ToString().StartsWith("21") ||
packet.DestinationAddress.ToString().StartsWith("11");
if (hairpin)
{
UDP.SendSMS(packet.UserData.ToString(), packet.DestinationAddress.ToString(), FromAddress.ToString());
break;
}
Http.SendSMS(packet.UserData.ToString(), packet.DestinationAddress.ToString(), "");
break;
default:
break;
}
}
示例3: GetDataSeriesInfo
public static DataSeriesInfo GetDataSeriesInfo(string seriesName)
{
DataSeriesInfo dataSeriesInfo = new DataSeriesInfo();
dataSeriesInfo.SeriesName = seriesName;
List<string> list = new List<string>((IEnumerable<string>)seriesName.Split(new char[] { '.' }));
dataSeriesInfo.DataType = DataType.Unknown;
switch (list[list.Count - 1])
{
case "Daily":
dataSeriesInfo.DataType = DataType.Daily;
break;
case "Trade":
dataSeriesInfo.DataType = DataType.Trade;
break;
case "Quote":
dataSeriesInfo.DataType = DataType.Quote;
break;
case "Depth":
dataSeriesInfo.DataType = DataType.MarketDepth;
break;
}
int count = 1;
long result;
if (dataSeriesInfo.DataType == DataType.Unknown && list.Count >= 4 && (list[list.Count - 3] == "Bar" && Enum.IsDefined(typeof(BarType), (object)list[list.Count - 2])) && long.TryParse(list[list.Count - 1], out result))
{
dataSeriesInfo.DataType = DataType.Bar;
dataSeriesInfo.BarType = (BarType)Enum.Parse(typeof(BarType), list[list.Count - 2]);
dataSeriesInfo.BarSize = result;
count = 3;
}
dataSeriesInfo.Symbol = string.Join('.'.ToString(), list.GetRange(0, list.Count - count).ToArray());
dataSeriesInfo.Suffix = string.Join('.'.ToString(), list.GetRange(list.Count - count, count).ToArray());
return dataSeriesInfo;
}
示例4: SplitShaders
/// <summary>
/// Splits the shaders.
/// </summary>
/// <param name="shaderBuffer">The shader buffer.</param>
private Shader SplitShaders(List<string> shaderBuffer,ref string name){
int vertexShaderOffset=0, fragmentShaderOffset=0, lineCount=0;
string version="";
foreach (string line in shaderBuffer)
{
if (line.Contains("#pragma vertex")) {
vertexShaderOffset = lineCount + 1;
} else if (line.Contains("#pragma fragment")) {
fragmentShaderOffset = lineCount + 1;
} else if (line.Contains ("#version")) {
version = line;
}
lineCount++;
}
List<string> vertexShaderBuffer =
shaderBuffer.GetRange(vertexShaderOffset, fragmentShaderOffset-vertexShaderOffset);
vertexShaderBuffer.Insert (0, version);
List<string> fragmentShaderBuffer =
shaderBuffer.GetRange(fragmentShaderOffset, lineCount-fragmentShaderOffset);
fragmentShaderBuffer.Insert (0, version);
string vertexShader, fragmentShader;
ProcessIncludes(vertexShaderBuffer, out vertexShader);
ProcessIncludes(fragmentShaderBuffer, out fragmentShader);
return new Shader (ref vertexShader,ref fragmentShader,ref name);
}
示例5: Parse
/// <summary>
/// Parses csv to TestCases
/// </summary>
/// <param name="data">data parameter</param>
/// <param name="resources">resources parameter</param>
/// <returns>TestCase list</returns>
public static TestCases Parse(List<List<string>> data, ResourceManager resources = null)
{
if (data == null || !data.Any()) { throw new ArgumentNullException("data"); }
var rootHeader = HeaderParser.Parse(data);
HeaderValidator.Validate(rootHeader);
var cases = new TestCases();
var lastStartIndex = 0;
for (var i = HeaderParser.HeaderRowCount; i < data.Count; i++)
{
var row = data[i];
if (!string.IsNullOrWhiteSpace(row[0]))
{
if (i != HeaderParser.HeaderRowCount)
{
cases.Add(TestCaseParser.Parse(rootHeader, data.GetRange(lastStartIndex, i - lastStartIndex), resources));
}
lastStartIndex = i;
}
}
cases.Add(TestCaseParser.Parse(rootHeader, data.GetRange(lastStartIndex, data.Count - lastStartIndex), resources));
return cases;
}
示例6: Sort
public override List<int> Sort(List<int> listToSort)
{
// Create a new deep copy of the list to avoid conflicts
List<int> resultList = new List<int>(listToSort);
// Trivial case
if (resultList.Count <= 1)
{
return resultList;
}
// Determine middle index of the data set
int middleIndex = resultList.Count / 2;
// Split data into two vectors
List<int> leftSubList = resultList.GetRange(0, middleIndex);
List<int> rightSubList = resultList.GetRange(middleIndex, resultList.Count - middleIndex);
// Recursive merge sort of the two vectors
leftSubList = Sort(leftSubList);
rightSubList = Sort(rightSubList);
// Merge sorted reults
return merge(leftSubList, rightSubList);
}
示例7: Test
/// <summary>
///
/// </summary>
/// <param name="ipds"></param>
/// <param name="sampleSize"></param>
/// <param name="windowSize"></param>
public static List<decimal> Test(List<decimal> ipds, int sampleSize, int windowSize)
{
List<decimal> results = new List<decimal>();
while (ipds.Count > 0)
{
List<decimal> sampleIpds;
if (ipds.Count > sampleSize)
{
sampleIpds = ipds.GetRange(0, sampleSize);
ipds.RemoveRange(0, sampleSize);
}
else
{
sampleIpds = ipds.GetRange(0, ipds.Count);
ipds.Clear();
}
decimal result = CalculateRegularity(sampleIpds, windowSize);
results.Add(result);
}
return results;
}
示例8: SimplifyLine
private static List<Point> SimplifyLine(List<Point> points, double eps)
{
Line l = new Line(points[0], points[points.Count - 1]);
double maxDist = 0;
int maxIndex = 0;
for (int i = 1; i < points.Count - 1; i++) {
double dist = l.PointDistance(points[i]);
if (dist > maxDist)
{
maxDist = dist;
maxIndex = i;
}
}
if (maxDist > eps)
{
List<Point> newPoints = new List<Point>();
List<Point> list1 = points.GetRange(0, maxIndex);
List<Point> list2 = points.GetRange(maxIndex, points.Count - maxIndex);
list1 = SimplifyLine(list1, eps);
list2 = SimplifyLine(list2, eps);
newPoints.AddRange(list1);
newPoints.RemoveAt(newPoints.Count - 1);
newPoints.AddRange(list2);
return newPoints;
}
else
{
List<Point> newPoints = new List<Point>();
newPoints.Add(points[0]);
newPoints.Add(points[points.Count - 1]);
return newPoints;
}
}
示例9: DesignExpected
/// <summary>
/// An estimated characteristic of occurrence of the subject word in the sequence
/// </summary>
/// <param name="accord">
/// Checking word.
/// </param>
/// <param name="chainLength">
/// Length of whole sequence.
/// </param>
/// <param name="winLen">
/// Length of the scanning window.
/// </param>
/// <param name="minusOne">
/// Data for "minus one" subword.
/// </param>
/// <param name="mid">
/// Data for "minus two" subword.
/// </param>
/// <returns>
/// Design characteristic of occurrence of the word.
/// </returns>
public double DesignExpected(List<string> accord, int chainLength, int winLen, DataCollector minusOne, DataCollector mid)
{
int shortWord = 2;
int midlLength = winLen - 2;
int minusLength = winLen - 1;
List<int> left = minusOne.Positions(accord.GetRange(0, accord.Count - 1));
List<int> right = minusOne.Positions(accord.GetRange(1, accord.Count - 1));
List<int> middle = midlLength != 0 ? mid.Positions(accord.GetRange(1, accord.Count - 2)) : new List<int>();
double criteria = -1;
if (winLen == shortWord)
{
criteria = Frequency(left, chainLength, minusLength)
* Frequency(right, chainLength, minusLength);
}
else if (middle != null)
{
criteria = (Frequency(left, chainLength, minusLength)
* Frequency(right, chainLength, minusLength))
/ Frequency(middle, chainLength, midlLength);
}
return criteria;
}
示例10: RealAllAsync
public static void RealAllAsync(List<FilePathInfo> pathList)
{
int needThreadCount = 1;
if (needThreadCount > 1)
{
int piece = pathList.Count / needThreadCount;
for (int i = 0; i < needThreadCount - 1; i++)
{
new ReadFileThread(pathList.GetRange(i * piece, piece));
}
new ReadFileThread(pathList.GetRange((needThreadCount - 1) * piece, pathList.Count - (needThreadCount - 1) * piece));
}
else
{
new ReadFileThread(pathList);
}
while (true)
{
Thread.Sleep(1000);
if (finThreadCount == needThreadCount)
{
break;
}
}
}
示例11: Compare
/// <summary>
/// 比较两个结果文件CnpA、CnpB,并将比较结果存到第一个文件所在的目录下
/// CnpAAndCnpB.Cnp,CnpAOrCnpB.Cnp,CnpANotCnpB.Cnp,CnpBNotCnpA.Cnp
/// return value: hashtable, values list as follows
/// key:"lst1AndLst2", value:CnpAAndCnpB中的结果数
/// key:"lst1OrLst2", value:CnpAOrCnpB中的结果数 totalNum
/// key:"lst1NotLst2", value:CnpANotCnpB中的结果数 addNum
/// key:"lst2NotLst1", value:CnpBNotCnpA中的结果数 deleteNum
/// </summary>
public Hashtable Compare(String filePath1, byte[] file)
{
List<int> lst1 = GetResultList(filePath1);
List<int> lst2 = new List<int>();
List<int> lst1AndLst2 = new List<int>();
List<int> lst1OrLst2 = new List<int>();
List<int> lst1NotLst2 = new List<int>();
List<int> lst2NotLst1 = new List<int>();
int lstLength1 = lst1.Count;
int lstLength2 = lst2.Count;
int i = 0; // lst1的指针
int j = 0; // lst2的指针
for (; i < lstLength1 && j < lstLength2; )
{
if (lst1[i] == lst2[j])
{
lst1AndLst2.Add(lst1[i]);
lst1OrLst2.Add(lst1[i]);
i++;
j++;
}
else if (lst1[i] > lst2[j])
{
lst2NotLst1.Add(lst2[j]);
lst1OrLst2.Add(lst2[j]);
j++;
}
else if (lst1[i] < lst2[j])
{
lst1NotLst2.Add(lst1[i]);
lst1OrLst2.Add(lst1[i]);
i++;
}
}
// 将lst2的剩下的内容存入list
if (lstLength1 == i)
{
lst2NotLst1.AddRange(lst2.GetRange(j, lstLength2 - j));
lst1OrLst2.AddRange(lst2.GetRange(j, lstLength2 - j));
}
// 将lst1的剩下的内容存入list
else if (lstLength2 == j)
{
lst1NotLst2.AddRange(lst1.GetRange(i, lstLength1 - i));
lst1OrLst2.AddRange(lst1.GetRange(i, lstLength1 - i));
}
Hashtable resultNum = new Hashtable();
//resultNum.Add("lst1AndLst2", lst1AndLst2.Count);
//resultNum.Add("lst1OrLst2", lst1OrLst2.Count);
//resultNum.Add("lst1NotLst2", lst1NotLst2.Count);
//resultNum.Add("lst2NotLst1", lst2NotLst1.Count);
lst1OrLst2.AddRange(lst2NotLst1);
resultNum.Add("Num", lst1NotLst2.Count);
resultNum.Add("File", lst1NotLst2.ToArray());
return resultNum;
}
示例12: evaluate
//Public entry function. All evaluations start here. If the expression is empty, return zero.
//If the new operand is the start of a bracketed term, continue evaluating with an accumulator to collect the terms inside the brackets.
//Otherwise, peel off the first number and continue evaluating.
public static float evaluate(List<object> expression){
if(expression.Count==0)
return 0.0f;
else if(expression[0].GetType()==typeof(OpenBracket))
return evaluate (new List<object>(), expression.GetRange(1, expression.Count-1));
return evaluate ((float)expression[0], expression.GetRange(1, expression.Count-1));
}
示例13: GetPlayerList
// Player list is needed in OnPlayerList, OnPlayerLeave and server.onRoundOverPlayers
public new static List<CPlayerInfo> GetPlayerList(List<string> words) {
List<CPlayerInfo> lstReturnList = new List<CPlayerInfo>();
int currentOffset = 0;
int parameterCount = 0;
int playerCount = 0;
if (words.Count > currentOffset && int.TryParse(words[currentOffset++], out playerCount) == true) {
if (words.Count > 0 && int.TryParse(words[currentOffset++], out parameterCount) == true) {
List<string> lstParameters = words.GetRange(currentOffset, parameterCount);
currentOffset += parameterCount;
for (int i = 0; i < playerCount; i++) {
if (words.Count > currentOffset + (i * parameterCount)) {
lstReturnList.Add(new CPlayerInfo(lstParameters, words.GetRange(currentOffset + i * parameterCount, parameterCount)));
}
}
}
}
return lstReturnList;
}
示例14: computeAutocorr
//autocorr
public static double computeAutocorr(List<double> values)
{
if (values.Count < 3) return 0;
List<double> originList = values.GetRange(0, values.Count - 1),
shiftedList = values.GetRange(1, values.Count - 1);
return Statistics.Covariance(originList, shiftedList) / (Statistics.StandardDeviation(originList) * Statistics.StandardDeviation(shiftedList));
}
示例15: MergeSort
static List<int> MergeSort(List<int> list)
{
if (list.Count < 2)
return list;//прекъсване на рекурсията, няма нужда да се сортира 1 елемент - връщаме list непроменен
List<int> left = MergeSort( list.GetRange( 0, list.Count/2 ) );//сортирам лявата половина на списъка
List<int> right = MergeSort( list.GetRange( left.Count, list.Count - left.Count ) );//сортирам дясната половина на списъка
List<int> result = new List<int>();
//left и right са сортирани, обединявам двата списъка в result:
while (left.Count > 0 && right.Count > 0)//докато някой от двата списъка не се изпразни...
{
//...сравнявам първите елементи от двата списъка, премествам по-малкия в result
if (left[0]<=right[0])
{
result.Add(left[0]);
left.RemoveAt(0);
}
else
{
result.Add(right[0]);
right.RemoveAt(0);
}
}
//ако някой от двата списъка все още не е празен (поне 1 от тях е празен) - добавям го в result
result.AddRange(left);
result.AddRange(right);
return result;
}