Eşit Parçalara Bölme Ve Kullanma
-
Şöyle birşey yapıyorum. Elimde 5542 elemanlı bir array-dizi-list var. Bu diziyi 1000'lik eşit parçalara bölüp işlem yapıyorum. Bunun için şöyle bir kod yazdım ancak durumdan memnun olmadım sanki kada kısa bir kodla yazılabilir gibi geliyor. Hem bana hemde ilgilenenlere eğlence olur:
Benim yazdığım kod şöyle:
int forCount = segmentList.Count / 1000; for (int i = 0; i < forCount; i++) { string sendText = String.Join(Environment.NewLine, segmentList.Select(xXx => xXx.SourceSegment).Skip(1000 * i).Take(1000).ToList()); int kacVeriimAbime = segmentList.Select(xXx => xXx.SourceSegment).Skip(1000 * i).Take(1000).ToList().Count; } int modCount = segmentList.Count % 1000; if (modCount > 0) { string sendText = String.Join(Environment.NewLine, segmentList.Select(xXx => xXx.SourceSegment).Skip(1000 * forCount).ToList()); int kacVeriimAbime =segmentList.Select(xXx => xXx.SourceSegment).Skip(1000 * forCount).ToList().Count; } -
bu şekil işine yararmı hocam?
string[] items = Enumerable.Range(1, 100).Select(i => "Item" + i).ToArray();
HolyOne tarafından 17/Eyl/13 08:53 tarihinde düzenlenmiştir
String[][] chunks = items
.Select((s, i) => new { Value = s, Index = i })
.GroupBy(x => x.Index / 11)
.Select(grp => grp.Select(x => x.Value).ToArray())
.ToArray();
Toplam Hit: 808 Toplam Mesaj: 2
