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


C# System.Join方法代码示例

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


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

示例1: Eval

      public int Eval(string args) {
         string propertyName;
         args = Tokenizer.Next(args, out propertyName);

         SomeNode propertyNode;
         if (!ReplGlobals.Current.TryGetChild(propertyName, out propertyNode)) {
            throw new Exception($"Couldn't find property of name {propertyNode}.");
         }

         var propertyDto = propertyNode.PropertyDto;

         if (!propertyDto.HasSetter) {
            throw new Exception($"Property {propertyName} does not have a setter.");
         }

         string valueString;
         Tokenizer.Next(args, out valueString);
         object value = Convert.ChangeType(valueString, propertyDto.Type);

         var parameters = new[] { value };

         Console.WriteLine($"Invoking {propertyName} setter with params ({parameters.Join(", ")}.");

         var mobDto = propertyNode.Parent.MobDto;
         var result = ReplGlobals.ManagementObjectService.InvokeManagedOperationAsync(mobDto.FullName, propertyName, parameters).Result;

         Console.WriteLine("Result: ");
         ReplUtils.PrettyPrint(result);
         return 0;
      }
开发者ID:the-dargon-project,项目名称:courier,代码行数:30,代码来源:InvokeCommand.cs

示例2: ShoudSelectIn

 public void ShoudSelectIn()
 {
     var list = new[] {1, 2, 3, 4, 5};
     var inClause = new[] {1, 5};
     var resultList = list.Join(inClause, x => x, y => y, (x, y) => x);
     Assert.IsTrue(inClause.SequenceEqual(resultList));
 }
开发者ID:gobixm,项目名称:learn,代码行数:7,代码来源:LinqTest.cs

示例3: TestReadBlock

 public void TestReadBlock()
 {
     var strings = new[] { "some", "new", "stuff" };
     string singleString = strings.Join(Environment.NewLine);
     var stringsTextReader = new StringsTextReader(strings);
     var buff = new char[8];
     Assert.AreEqual(8, stringsTextReader.ReadBlock(buff, 0, 8));
     Assert.AreEqual(singleString.Substring(0, 8), new string(buff));
 }
开发者ID:antiufo,项目名称:ntextcat,代码行数:9,代码来源:TestStringsTextReader.cs

示例4: Join_JoinStrings

        public void Join_JoinStrings()
        {
            var strings = new[]
            {
                "a", "b", "c"
            };

            Assert.Equal("a,b,c", strings.Join(","));
        }
开发者ID:hightechtoday,项目名称:costeffectivecode,代码行数:9,代码来源:StringExtensionsTests.cs

示例5: ReferenceOuter_ReferenceInner_ValueKey_ReferenceResult

        public void ReferenceOuter_ReferenceInner_ValueKey_ReferenceResult()
        {
            string[] outer = new [] {"0", "1", "2", "3", "4", "5", "6"};
            string[] inner = new [] {"0", "1", "2", "3", "4", "5", "6"};

            IEnumerable<string> result = outer.Join<string, string, int, string> (inner: inner, outerKeySelector: it => int.Parse (it), innerKeySelector: it => int.Parse (it), resultSelector: (o, i) => o);
            Assert.That (result.Count (), Is.EqualTo (result.Count ()));
            for (int i = 0; i < outer.Length; i++) {
                Assert.That (outer [i], Is.EqualTo (result.ElementAt (i)));
            }
        }
开发者ID:ELN,项目名称:UniLinq,代码行数:11,代码来源:JoinTest.cs

示例6: ReferenceOuter_ReferenceInner_ReferenceKey_ReferenceResult_Comparer

        public void ReferenceOuter_ReferenceInner_ReferenceKey_ReferenceResult_Comparer()
        {
            IEqualityComparer<string> comparer = EqualityComparer<string>.Default;
            string[] outer = new [] {"0", "1", "2", "3", "4", "5", "6"};
            string[] inner = new [] {"0", "1", "2", "3", "4", "5", "6"};

            IEnumerable<string> result = outer.Join<string, string, string, string> (inner: inner, outerKeySelector: it => it, innerKeySelector: it => it, resultSelector: (o, i) => o, comparer: comparer);
            Assert.That (result.Count (), Is.EqualTo (result.Count ()));
            for (int i = 0; i < outer.Length; i++) {
                Assert.That (outer [i], Is.EqualTo (result.ElementAt (i)));
            }
        }
开发者ID:ELN,项目名称:UniLinq,代码行数:12,代码来源:JoinTest.cs

示例7: TestRead

 public void TestRead()
 {
     var strings = new[] { "some", "new", "stuff" };
     var stringsTextReader = new StringsTextReader(strings);
     foreach (char c in strings.Join(Environment.NewLine))
     {
         Assert.AreEqual((int)c, stringsTextReader.Read());
     }
     Assert.AreEqual(-1, stringsTextReader.Read());
     Assert.AreEqual(-1, stringsTextReader.Read());
     Assert.AreEqual(null, stringsTextReader.ReadLine());
     Assert.AreEqual(-1, stringsTextReader.Peek());
 }
开发者ID:antiufo,项目名称:ntextcat,代码行数:13,代码来源:TestStringsTextReader.cs

示例8: InnerSequenceIsBuffered

        public void InnerSequenceIsBuffered()
        {
            var outer = new[] { 1, 2, 3 };
            var inner = new[] { 10, 0, 2 }.Select(x => 10 / x);
            var query = outer.Join(inner, x => x, y => y, (x, y) => x + y);

            using (var iterator = query.GetEnumerator())
            {
                // Even though we could sensibly see the first element before anything
                // is returned, that doesn't happen: the inner sequence is read completely
                // before we start reading the outer sequence
                Assert.Throws<DivideByZeroException>(() => iterator.MoveNext());
            }
        }
开发者ID:kolinlob,项目名称:kottans-csharp,代码行数:14,代码来源:JoinTest.cs

示例9: OuterSequenceIsStreamed

        public void OuterSequenceIsStreamed()
        {
            var outer = new[] { 10, 0, 2 }.Select(x => 10 / x);
            var inner = new[] { 1, 2, 3 };
            var query = outer.Join(inner, x => x, y => y, (x, y) => x + y);

            using (var iterator = query.GetEnumerator())
            {
                // First element is fine
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(2, iterator.Current);

                // Attempting to get to the second element causes division by 0
                Assert.Throws<DivideByZeroException>(() => iterator.MoveNext());
            }
        }
开发者ID:ungood,项目名称:EduLinq,代码行数:16,代码来源:JoinTests.cs

示例10: GetUserName

        public static string GetUserName(string name = null)
        {
            if (name != null)
            {
                string parts = name.Split(' ').Join(new[] { ".", "_" }.Rand());
                return parts.ToLower();
            }
            else
            {
                switch (FakerRandom.Rand.Next(2))
                {
                    case 0:
                        return new Regex(@"\W").Replace(Name.GetFirstName(), "").ToLower();
                    case 1:
                        var parts = new[] { Name.GetFirstName(), Name.GetLastName() }.Select(n => new Regex(@"\W").Replace(n, ""));
						return parts.Join(new[] { ".", "_" }.Rand()).ToLower();
                    default: throw new ApplicationException();
                }
            }
        }
开发者ID:bbqchickenrobot,项目名称:Faker.Net,代码行数:20,代码来源:Internet.cs

示例11: Abort

        public static void Abort(ref System.Threading.Thread thread, System.TimeSpan timeout, System.Threading.ThreadState state = System.Threading.ThreadState.Stopped)
        {
            //If the worker IsAlive and has the requested state.
            if (thread != null && (thread.IsAlive && thread.ThreadState.HasFlag(state)))
            {
                //Attempt to join
                if (false == thread.Join(timeout))
                {
                    try
                    {
                        //Abort
                        thread.Abort();
                    }
                    catch (System.Threading.ThreadAbortException) { System.Threading.Thread.ResetAbort(); }
                    catch { throw; } //Cancellation not supported
                }

                //Reset the state of the thread to indicate success
                thread = null;
            }
        }
开发者ID:qinpengit,项目名称:net7mma-111212,代码行数:21,代码来源:ThreadExtensions.cs

示例12: FirstOuterMatchesLastInnerLastOuterMatchesFirstInnerSameNumberElements

        public void FirstOuterMatchesLastInnerLastOuterMatchesFirstInnerSameNumberElements()
        {
            CustomerRec[] outer = new []
            {
                new CustomerRec{ name = "Prakash", custID = 98022 },
                new CustomerRec{ name = "Tim", custID = 99021 },
                new CustomerRec{ name = "Robert", custID = 99022 }
            };
            OrderRec[] inner = new []
            {
                new OrderRec{ orderID = 45321, custID = 99022, total = 50 },
                new OrderRec{ orderID = 43421, custID = 29022, total = 20 },
                new OrderRec{ orderID = 95421, custID = 98022, total = 9 }
            };
            JoinRec[] expected = new []
            {
                new JoinRec{ name = "Prakash", orderID = 95421, total = 9 },
                new JoinRec{ name = "Robert", orderID = 45321, total = 50 }
            };

            Assert.Equal(expected, outer.Join(inner, e => e.custID, e => e.custID, createJoinRec));
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:22,代码来源:JoinTests.cs

示例13: JoinSample

        private void JoinSample()
        {
            string[] names = new[] {"Robin", "Ruth", "Bob", "Emma"};
            string[] colors = new[] {"Red", "Blue", "Beige", "Green"};

            List<string> list = names.Join(colors, name => name[0], color => color[0], (name, color) => name + "-" + color).ToList();
            System.Console.WriteLine("result sequence:");
            foreach(var item in list)
            System.Console.WriteLine(item);

            //Func<string, int> calc = s => s.Length;

            
        }
开发者ID:Stanols,项目名称:Samples,代码行数:14,代码来源:StandartLinqOperationsSample.cs

示例14: GetCompilerDefines

        protected string GetCompilerDefines()
        {
            var defines = new[] {
                "/d:Framework_4_0"
            };

            return defines.Join(" ");
        }
开发者ID:GodLesZ,项目名称:ZeusEngine,代码行数:8,代码来源:ScriptCompiler.cs

示例15: should_join_strings

 public void should_join_strings()
 {
     var values = new[] { "a", "sequence", "of", "strings" };
     values.Join(",").Should().Be("a,sequence,of,strings");
     values.Join("|").Should().Be("a|sequence|of|strings");
 }
开发者ID:yonglehou,项目名称:Crux,代码行数:6,代码来源:StringExtensionsTester.cs


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