当前位置: 首页>>代码示例>>C#>>正文


C# List.ToLookup方法代码示例

本文整理汇总了C#中NUnit.Framework.List.ToLookup方法的典型用法代码示例。如果您正苦于以下问题:C# List.ToLookup方法的具体用法?C# List.ToLookup怎么用?C# List.ToLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NUnit.Framework.List的用法示例。


在下文中一共展示了List.ToLookup方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToLookupOfStringReturnsCorrectLookup

        public void ToLookupOfStringReturnsCorrectLookup()
        {
            // Given
            Engine engine = new Engine();
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument a = new Document(engine, pipeline)
                .Clone("a", new[] { new KeyValuePair<string, object>("Numbers", new[] { 1, 2, 3 }) });
            IDocument b = new Document(engine, pipeline)
                .Clone("b", new[] { new KeyValuePair<string, object>("Numbers", new[] { 2, 3, 4 }) });
            IDocument c = new Document(engine, pipeline)
                .Clone("c", new[] { new KeyValuePair<string, object>("Numbers", 3) });
            IDocument d = new Document(engine, pipeline)
                .Clone("d", new[] { new KeyValuePair<string, object>("Numbers", "4") });
            List<IDocument> documents = new List<IDocument>() { a, b, c, d };

            // When
            ILookup<string, IDocument> lookup = documents.ToLookup<string>("Numbers");

            // Then
            Assert.AreEqual(4, lookup.Count);
            CollectionAssert.AreEquivalent(new[] { a }, lookup["1"]);
            CollectionAssert.AreEquivalent(new[] { a, b }, lookup["2"]);
            CollectionAssert.AreEquivalent(new[] { a, b, c }, lookup["3"]);
            CollectionAssert.AreEquivalent(new[] { b, d }, lookup["4"]);
        }
开发者ID:Chandu,项目名称:Wyam,代码行数:25,代码来源:DocumentCollectionExtensionsFixture.cs

示例2: ChangesToSourceSequenceAfterToLookupAreNotNoticed

        public void ChangesToSourceSequenceAfterToLookupAreNotNoticed()
        {
            List<string> source = new List<string> { "abc" };
            var lookup = source.ToLookup(x => x.Length);
            Assert.AreEqual(1, lookup.Count);

            // Potential new key is ignored
            source.Add("x");
            Assert.AreEqual(1, lookup.Count);

            // Potential new value for existing key is ignored
            source.Add("xyz");
            lookup[3].AssertSequenceEqual("abc");
        }
开发者ID:mdclement,项目名称:Linq--from-the-inside--Presentation-Base,代码行数:14,代码来源:ToLookupTests.cs

示例3: ReturnsCorrectLookupOfString

            public void ReturnsCorrectLookupOfString()
            {
                // Given
                IDocument a = new Document(
                    new InitialMetadata { { "Numbers", new[] { 1, 2, 3 } } }, "a");
                IDocument b = new Document(
                    new InitialMetadata { { "Numbers", new[] { 2, 3, 4 } } }, "b");
                IDocument c = new Document(
                    new InitialMetadata { { "Numbers", 3 } }, "c");
                IDocument d = new Document(
                    new InitialMetadata { { "Numbers", "4" } }, "d");
                List<IDocument> documents = new List<IDocument>() { a, b, c, d };

                // When
                ILookup<string, IDocument> lookup = documents.ToLookup<string>("Numbers");

                // Then
                Assert.AreEqual(4, lookup.Count);
                CollectionAssert.AreEquivalent(new[] { a }, lookup["1"]);
                CollectionAssert.AreEquivalent(new[] { a, b }, lookup["2"]);
                CollectionAssert.AreEquivalent(new[] { a, b, c }, lookup["3"]);
                CollectionAssert.AreEquivalent(new[] { b, d }, lookup["4"]);
            }
开发者ID:ryanrousseau,项目名称:Wyam,代码行数:23,代码来源:DocumentCollectionExtensionsTests.cs

示例4: ToLookupOfIntReturnsCorrectLookup

        public void ToLookupOfIntReturnsCorrectLookup()
        {
            // Given
            Engine engine = new Engine();
            IDocument a = new Document(new Metadata(engine))
                .Clone("a", new[] { new KeyValuePair<string, object>("Numbers", new [] { 1, 2, 3 }) });
            IDocument b = new Document(new Metadata(engine))
                .Clone("b", new[] { new KeyValuePair<string, object>("Numbers", new [] { 2, 3, 4 }) });
            IDocument c = new Document(new Metadata(engine))
                .Clone("c", new[] { new KeyValuePair<string, object>("Numbers", 3) });
            IDocument d = new Document(new Metadata(engine))
                .Clone("d", new[] { new KeyValuePair<string, object>("Numbers", "4") });
            List<IDocument> documents = new List<IDocument>() { a, b, c, d };

            // When
            ILookup<int, IDocument> lookup = documents.ToLookup<int>("Numbers");

            // Then
            Assert.AreEqual(4, lookup.Count);
            CollectionAssert.AreEqual(new[] { a }, lookup[1]);
            CollectionAssert.AreEqual(new[] { a, b }, lookup[2]);
            CollectionAssert.AreEqual(new[] { a, b, c }, lookup[3]);
            CollectionAssert.AreEqual(new[] { b, d }, lookup[4]);
        }
开发者ID:Rohansi,项目名称:Wyam,代码行数:24,代码来源:DocumentCollectionExtensionsFixture.cs

示例5: ToLookupWithValuesReturnsCorrectLookup

        public void ToLookupWithValuesReturnsCorrectLookup()
        {
            // Given
            Engine engine = new Engine();
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument a = new Document(engine, pipeline)
                .Clone("a", new[]
                {
                    new KeyValuePair<string, object>("Numbers", new[] { 1, 2, 3 }),
                    new KeyValuePair<string, object>("Colors", "Red") 
                });
            IDocument b = new Document(engine, pipeline)
                .Clone("b", new[]
                {
                    new KeyValuePair<string, object>("Numbers", new[] { 2, 3, 4 }),
                    new KeyValuePair<string, object>("Colors", new [] { "Red", "Blue" })
                });
            IDocument c = new Document(engine, pipeline)
                .Clone("c", new[]
                {
                    new KeyValuePair<string, object>("Numbers", 3),
                    new KeyValuePair<string, object>("Colors", "Green")
                });
            IDocument d = new Document(engine, pipeline)
                .Clone("d", new[]
                {
                    new KeyValuePair<string, object>("Numbers", "4"),
                    new KeyValuePair<string, object>("Colors", new [] { "Green", "Blue" })
                });
            List<IDocument> documents = new List<IDocument>() { a, b, c, d };

            // When
            ILookup<int, string> lookup = documents.ToLookup<int, string>("Numbers", "Colors");

            // Then
            Assert.AreEqual(4, lookup.Count);
            CollectionAssert.AreEquivalent(new[] { "Red" }, lookup[1]);
            CollectionAssert.AreEquivalent(new[] { "Red", "Blue" }, lookup[2]);
            CollectionAssert.AreEquivalent(new[] { "Red", "Blue", "Green" }, lookup[3]);
            CollectionAssert.AreEquivalent(new[] { "Red", "Blue", "Green" }, lookup[4]);
        }
开发者ID:Chandu,项目名称:Wyam,代码行数:41,代码来源:DocumentCollectionExtensionsFixture.cs

示例6: sampletest

 public void sampletest()
 {
     List<Person> s1 = new List<Person>();
     s1.Add(new Person(1, "oplok", "langit"));
     s1.Add(new Person(2, "oplo2k", "langit2"));
     List<Person> s2 = new List<Person>();
     s2.Add(new Person(1, "oplok", "langit3"));
     s2.Add(new Person(2, "loslos", "olympus2"));
     //List<Person> s3 = s1.Except(s2).ToList();
     var list2lookUp = s1.ToLookup(p => p.name);
     var listdiff = s2.Where(p => (!list2lookUp.Contains(p.name)));
     foreach(Person s in listdiff){
         Console.WriteLine(s.name + ": " + s.address);
     }
     Console.WriteLine("================================");
 }
开发者ID:ProximaCentauri,项目名称:pointofsale,代码行数:16,代码来源:LaundryTest.cs

示例7: Investigate

        public void Investigate()
        {
            var connection = new OleDbConnection();
            var mdb = @"c:\users\dan\desktop\rettig.mdb";
            var x = IntPtr.Size;
            connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + mdb;
            connection.Open();

            var koppling = new List<Tuple<int, int>>();
            using (var dr = (new OleDbCommand("SELECT mfd10070_id,mfd10015_id FROM mfd10071", connection)).ExecuteReader())
                while (dr.Read())
                    koppling.Add(new Tuple<int, int>(dr.GetInt32(0), dr.GetInt32(1)));

            var radiatortyp = new List<Tuple<int, int>>();
            using (var dr = (new OleDbCommand("SELECT id, mfd10010_id from mfd10015", connection)).ExecuteReader())
                while (dr.Read())
                {
                    var typeId = dr.GetInt32(1);
                    if (typeId < 9 ) //&& typeId != 7)
                        continue;
                    radiatortyp.Add(new Tuple<int, int>(dr.GetInt32(0), typeId));
                }

            var rts = radiatortyp.ToLookup(_ => _.Item2, _ => _.Item1);
            foreach (var rt in rts)
            {
                var allLuftDonMapings = new Dictionary<int, List<int>>();
                foreach (var rId in rt)
                {
                    allLuftDonMapings[rId] = koppling.Where(_ => _.Item2 == rId).Select(_ => _.Item1).Distinct().ToList();
                    foreach(var val in allLuftDonMapings.Values)
                        val.Sort();
                    if (!allEqual(allLuftDonMapings.Values.ToList()))
                    {
                    }
                }
            }
        }
开发者ID:danbystrom,项目名称:HeatOn,代码行数:38,代码来源:DatabaseExporter.cs

示例8: GroupingEnumerator

        public void GroupingEnumerator()
        {
            List<int> ints = new List<int> { 10, 20, 21, 30 };
            var lookup = new MutableLookup<int, int>(ints.ToLookup(i => Int32.Parse(i.ToString()[0].ToString())));

            Assert.AreEqual (2, lookup[2].Count());
            Assert.IsTrue (lookup[2].Any (i => i == 20));
            Assert.IsTrue (lookup[2].Any(i => i == 21));
        }
开发者ID:strager,项目名称:Tempest,代码行数:9,代码来源:MutableLookupTest.cs

示例9: EnumeratorNotNull

        public void EnumeratorNotNull()
        {
            List<string> strings = new List<string> { "hi", "hai", "bai", "bye" };
            var lookup = new MutableLookup<string, string> (strings.ToLookup (s => s[0].ToString()));

            Assert.AreEqual (2, lookup.Count);
            Assert.IsTrue (lookup.Any (g => g.Key == "h"));
            Assert.IsTrue (lookup.Any (g => g.Key == "b"));
            Assert.IsFalse (lookup.Any (g => g.Key == null));
        }
开发者ID:strager,项目名称:Tempest,代码行数:10,代码来源:MutableLookupTest.cs

示例10: Enumerator

        public void Enumerator()
        {
            List<int> ints = new List<int> { 10, 20, 21, 30 };
            var lookup = new MutableLookup<int, int>(ints.ToLookup(i => Int32.Parse(i.ToString()[0].ToString())));

            Assert.AreEqual (3, lookup.Count());
            Assert.IsTrue (lookup.Any (g => g.Key == 1));
            Assert.IsTrue (lookup.Any (g => g.Key == 2));
            Assert.IsTrue (lookup.Any (g => g.Key == 3));
        }
开发者ID:strager,项目名称:Tempest,代码行数:10,代码来源:MutableLookupTest.cs

示例11: CtorILookupWithNulls

        public void CtorILookupWithNulls()
        {
            List<string> strs = new List<string> { "Foo", "Foos", "Foobar", "Monkeys", "Bar", "Ban", "Barfoo" };

            var lookup = new MutableLookup<string, string> (strs.ToLookup (s => (s[0] != 'F' && s[0] != 'B') ? null : s[0].ToString()));
            Assert.AreEqual (3, lookup.Count);
            Assert.AreEqual (3, lookup["F"].Count());
            Assert.AreEqual (3, lookup["B"].Count());
            Assert.AreEqual (1, lookup[null].Count());
        }
开发者ID:strager,项目名称:Tempest,代码行数:10,代码来源:MutableLookupTest.cs

示例12: CtorILookup

        public void CtorILookup()
        {
            List<int> ints = new List<int> { 10, 20, 21, 30 };
            var lookup = new MutableLookup <int, int> (ints.ToLookup (i => Int32.Parse (i.ToString()[0].ToString())));

            Assert.AreEqual (3, lookup.Count);
            Assert.AreEqual (1, lookup[1].Count());
            Assert.AreEqual (2, lookup[2].Count());
            Assert.AreEqual (1, lookup[3].Count());
        }
开发者ID:strager,项目名称:Tempest,代码行数:10,代码来源:MutableLookupTest.cs

示例13: ReturnsCorrectLookupWithValues

            public void ReturnsCorrectLookupWithValues()
            {
                // Given
                IDocument a = new Document(
                    new InitialMetadata
                    {
                        { "Numbers", new[] { 1, 2, 3 } },
                        { "Colors", "Red" }
                    }, "a");
                IDocument b = new Document(
                    new InitialMetadata
                    {
                        { "Numbers", new[] { 2, 3, 4 } },
                        { "Colors", new [] { "Red", "Blue" } }
                    }, "b");
                IDocument c = new Document(
                    new InitialMetadata
                    {
                        { "Numbers", 3 },
                        { "Colors", "Green" }
                    }, "c");
                IDocument d = new Document(
                    new InitialMetadata
                    {
                        { "Numbers", "4" },
                        { "Colors", new [] { "Green", "Blue" } }
                    }, "d");
                List<IDocument> documents = new List<IDocument>() { a, b, c, d };

                // When
                ILookup<int, string> lookup = documents.ToLookup<int, string>("Numbers", "Colors");

                // Then
                Assert.AreEqual(4, lookup.Count);
                CollectionAssert.AreEquivalent(new[] { "Red" }, lookup[1]);
                CollectionAssert.AreEquivalent(new[] { "Red", "Blue" }, lookup[2]);
                CollectionAssert.AreEquivalent(new[] { "Red", "Blue", "Green" }, lookup[3]);
                CollectionAssert.AreEquivalent(new[] { "Red", "Blue", "Green" }, lookup[4]);
            }
开发者ID:ryanrousseau,项目名称:Wyam,代码行数:39,代码来源:DocumentCollectionExtensionsTests.cs


注:本文中的NUnit.Framework.List.ToLookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。