本文整理汇总了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;
}
示例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));
}
示例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));
}
示例4: Join_JoinStrings
public void Join_JoinStrings()
{
var strings = new[]
{
"a", "b", "c"
};
Assert.Equal("a,b,c", strings.Join(","));
}
示例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)));
}
}
示例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)));
}
}
示例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());
}
示例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());
}
}
示例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());
}
}
示例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();
}
}
}
示例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;
}
}
示例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));
}
示例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;
}
示例14: GetCompilerDefines
protected string GetCompilerDefines()
{
var defines = new[] {
"/d:Framework_4_0"
};
return defines.Join(" ");
}
示例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");
}