比较2个类对象

时间:2019-04-16 19:46:03

标签: c# class c#-4.0

我有2个类,一个是Tune.cs,另一个是Request.cs

Tune.cs

        public class Tune

        {
            /// <summary>
            /// Gets or sets the tuners.
            /// </summary>
            [JsonProperty]
            public IReadOnlyList<string> Tuners{ get; set; }

            /// <summary>
            /// Gets or sets the Tuning Location.
            /// </summary>
            [JsonProperty]
            public IReadOnlyList<string> TuningLocation{ get; set; }
    }

Request.cs

public class Request 
{
            /// <summary>
            /// Gets or sets the requests.
            /// </summary>
            [JsonProperty]
            public IReadOnlyList<string> Requests{ get; set; }

            /// <summary>
            /// Gets or sets the Tuning Location for Requests.
            /// </summary>
            [JsonProperty]
            public IReadOnlyList<string> TuningLocation{ get; set; }
    }

我想在这里做的是一列Tunes

(IList<Tunes> listoftunes )

我只想保存调谐位置与请求中的调谐位置相匹配的音乐列表。

我有这样的东西

foreach (var tune in listoftunes)
            {
                foreach (var tuninglocation in tune.tuninglocation)
                {
                    if (request.tuninglocation.Contains(tuninglocation))
                    {
                        newlist.add(tune);
                    }
                }
            }

这是正确的方法吗? 。是否有更好的方法来实现

0 个答案:

没有答案