Home > Net >  C # linq query problem.
C # linq query problem.

Time:10-12

If I database with 500000 data, I give a condition, the 2-5-6-2-5-6-4 represents a column of the first number, I find this condition of continuous lines of the next line, this what's the best thing to do, as shown in figure



I 'll get the 9, because the continuous line to satisfy the conditions, must be continuous, not short in the middle,


If you have a better way, can add my Qq: 68345106, this way can I pay cost,

CodePudding user response:

 IEnumerable Seq (& lt; List Data, n) 
{
for (int i=0; i Yield return data. The Skip (I) Take (n);
}

Void Main ()
{
List Data=https://bbs.csdn.net/topics/{" 23456 ", "57876", "63465",... };
String cond="2-5-6-2-5-6-4".
Var query=seq (data, cond. Split (' - '). The Count () + 1)
The Where (x=& gt; X.T ake (x.C mount () - 1). The Zip (cond. Split (' - '), (a, b)=& gt; A.S tartsWith). (b) All ())
The Select (x=& gt; X.L ast ());
The foreach (var item in the query)
Console. WriteLine (item);
}

CodePudding user response:

Why don't knot post, one's fingers itch to write down, vb code
Sub Main ()
For I=0 To 4
Console. WriteLine (" input filter number: ")
Dim MatchS=Console. ReadLine
Dim RLT=MatchNumber (MatchS)
If Not RLT Is Nothing Then RLT. ForEach (Sub (t) Console. WriteLine (t))
Next
The Console. The Read ()
End Sub
The Function MatchNumber (MatchS the As String) As the List (Of String)
Dim sList=MatchS. ToList
Dim TB=(New testDataDataContext). TpTest
Dim datalist=TB. Select (Function (Dr) New With {Key. Id=Dr. Id, the s1=Dr. ValueS. The Substring (0, 1)}), Where (Function (r) r.s 1 Equals (sList. First))
Dim OutTxt=New List (Of String)
The datalist. ToList. ForEach (Sub (Dr)
Dim MatchData=https://bbs.csdn.net/topics/tb.Where (Function (r)>=Dr. R.i d id), Select (Function (x) New With {Key. Id=x.i d,. S1=x.V alueS. Substring (0, 1)}), Take (sList. Count)
Dim CompareS=String. Join (" ", MatchData. Select (Function (r) r.s 1))
If CompareS. Equals (MatchS) Then
Dim curMaxId=MatchData. Max (Function (r) r.i d)
Dim rltDataRow=TB. The Where (Function (d) d.i d & gt; CurMaxId.) Take (1)
OutTxt. Add (rltDataRow. Select (Function (r) r.V alueS). The ToArray (0))
End the If
End Sub)
If OutTxt. Count & gt; 0 Then
Return OutTxt
The Else
Return Nothing
End the If
End the Function

CodePudding user response:

reference 1st floor caozhy response:
 IEnumerable Seq (& lt; List Data, n) 
{
for (int i=0; i Yield return data. The Skip (I) Take (n);
}

Void Main ()
{
List Data=https://bbs.csdn.net/topics/{" 23456 ", "57876", "63465",... };
String cond="2-5-6-2-5-6-4".
Var query=seq (data, cond. Split (' - '). The Count () + 1)
The Where (x=& gt; X.T ake (x.C mount () - 1). The Zip (cond. Split (' - '), (a, b)=& gt; A.S tartsWith). (b) All ())
The Select (x=& gt; X.L ast ());
The foreach (var item in the query)
Console. WriteLine (item);
}


This is a positive solution, sharp, iteration is used is really beautiful,, the author to VB code
Sub TestIterators (MatchS the As String)
Dim datacontext=New testDataDataContext
Dim TB=datacontext. TpTest
Dim dataList=TB. Select (Function (Dr) Dr. ValueS). The ToList
Dim iterator1=Iterator Function (data1 As List (Of String), n (As an Integer)
For I=0 To data1. Count - n
Yield data1. Skip (I) Take (n)
Next
End the Function
Dim qry=iterator1 (dataList, MatchS. ToArray. Count + 1), Where (Function (x) x.T ake (x.C mount - 1). The Zip (MatchS ToList, Function (a, b) a.S tartsWith (b)). All (Function (c) c=True)). Select (Function (RLT) RLT. Last)
If qry. Count & gt; 0 Then
Qry. ToList. ForEach (Sub (x) Console. WriteLine (x.T oString))
End the If
Datacontext. The Dispose ()
End Sub
  •  Tags:  
  • LINQ
  • Related