1

これをクエリにリファクタリングしようとしています:

 while (IsRunning)
 {

 ...

 //specialPoint is a string
 foreach (PointTypeItem pointTypeItem in PointTypeItemCollection)
    {
        foreach (PointItem pointItem in pointTypeItem.PointItemCollection)
        {
            //Replace the point name with point ID
            if (specialPoint.Contains(pointItem.PointName))
            {
                replacedCode += s.Replace(specialPoint , pointItem.ID);
                //I want to go back to the beginning point of while (IsRunning) from here
                //Simply putting continue; here won't work
            }
        }
    }
 }

基本的にこれをLINQクエリに変換したいのですが、記述に行き詰まっています。実際、これが正しい方向に進んでいるかどうかさえわかりません。

var results = from pointTypeItem in ddcItem.PointTypeItemCollection
              where pointTypeItem.PointItemCollection.Any(pointItem => pointName.Contains(pointItem.PointName))
              select //What do I select?
4

3 に答える 3

6
var results = from pointTypeItem in ddcItem.PointTypeItemCollection
              from pointItem in pointTypeItem.PointItemCollection
              where specialPoint.Contains(pointItem.PointName)
              select pointItem.ID;

を取得します。IEnumerable<the type of pointItem.ID>

于 2012-11-20T13:27:39.640 に答える
2

これは、SelectMany()拡張メソッドを使用して行うことができます。

 PointTypeItemCollection.SelectMany(pointCollection => pointCollection.PointItemCollection)
                .Where(pointItem => pointItem.PointName.Contains(specialPoint))
                .Select(pointItem => pointItem.ID);
于 2012-11-20T13:31:14.093 に答える
0

It's very hard to test without having any values but what about something like this?

      replacedCode = string.Concat(
        this.PointTypeItemCollection.SelectMany(i => i.PointItemCollection)
        .Where(i => specialPoint.Contains(i.PointName))
        .Select(i => s.Replace(specialPoint, i.ID))
      );
于 2012-11-20T13:32:39.707 に答える