本文整理汇总了C#中System.String.Aggregate方法的典型用法代码示例。如果您正苦于以下问题:C# String.Aggregate方法的具体用法?C# String.Aggregate怎么用?C# String.Aggregate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.Aggregate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateDeck
public static string GenerateDeck(int seed)
{
var cards = string.Empty;
String[] suit = { "C", "S", "H", "D" };
String[] rank =
{
"2", "3", "4", "5", "6", "7", "8", "9", "10",
"J", "Q", "K", "A"
};
// initialize cards in a deck
var deck = new String[suit.Length * rank.Length];
for (var i = 0; i < rank.Length; i++)
for (var j = 0; j < suit.Length; j++)
deck[suit.Length*i + j] = rank[i] + suit[j];
// shuffle deck
var d = deck.Length;
var rand = new Random(seed);
for (var i = 0; i < d; i++)
{
var r = i + (int) (rand.NextDouble() * (d-i));
var temp = deck[r];
deck[r] = deck[i];
deck[i] = temp;
}
var generateDeck = deck.Aggregate(cards, (current, s) => current + (s + " "));
Console.WriteLine(generateDeck);
return generateDeck;
}
示例2: FourCharToInt
/// <summary>
/// Converts a four-char value to an unsigned integer.
/// </summary>
/// <param name = "fourCharValue">The four char value.</param>
/// <returns>An unsigned integer</returns>
public static uint FourCharToInt(String fourCharValue)
{
if (fourCharValue.Length != 4)
{
throw new ArgumentException();
}
return fourCharValue.Aggregate(0u, (i, c) => (i*256) + c);
}
示例3: Main
public static void Main(String[] args)
{
// This fixes the current directory in case it is run from outside the launcher path.
Environment.CurrentDirectory = Path.GetDirectoryName(typeof(SharpCraftApplication).Assembly.Location);
// Check for optional map specified to launch
string mapFile = ""; // Is there a loadfile arg specified?
for (var i = 0; i < args.Length; i++)
{
if (args[i] == "-loadfile" && args.Last() != "-loadfile") // if -loadfile and there are still more args to read
{
// check the argument immediately to the right... it should be a map file (w3x or w3m) or a replay (w3g)
if (args[i + 1].EndsWith(".w3x") || args[i + 1].EndsWith(".w3m") || args[i + 1].EndsWith(".w3g"))
{
mapFile = args[i + 1];
// clean string and wrap in quotes because path may contain spaces
// note: even when passing in the arg in quotes, those will "disappear", so quotes are re-applied
args[i + 1] = "\"" + args[i + 1].Trim() + "\"";
}
else
{
Console.WriteLine("The -loadfile param was specified, but was not immediately followed by a valid WarCraft map to open.");
}
}
else
{
Console.WriteLine("The -loadfile param was specified, but no more valid arguments follow it!");
}
}
if (args.Contains("-game") || args.Contains("-editor"))
{
Debug.WriteLineIf(args.Contains("-game"), args.Aggregate((a, b) => a + ' ' + b));
Debug.WriteLineIf(mapFile.Length > 0, "Starting game with map: " + mapFile);
StartDirect(args);
}
else
{
StartLauncher(args);
}
}
示例4: Deliminated
protected virtual String Deliminated(String deliminator, String[] strings)
{
return strings
.Aggregate("", (a, s) => (a == "" ? a : a + deliminator) + s);
}
示例5: hashCode
///
/// <param name="values"></param>
public static int hashCode(String[] values)
{
return values.Aggregate(31, (current, t) => current ^ t.GetHashCode());
}
示例6: StartEditor
public static void StartEditor(String[] args)
{
if (!Common.IsInitialized)
Common.Initialize();
if (!File.Exists(Common.EditorPath))
throw new FileNotFoundException("Could not find worldedit.exe!" + Environment.NewLine + "You may need to verify your registry settings are correct.", "worldedit.exe");
if (!File.Exists(Path.Combine(Environment.CurrentDirectory, "SharpCraft.dll")))
throw new FileNotFoundException("Could not find SharpCraft.dll!" + Environment.NewLine + "You may need to redownload SharpCraft.", "SharpCraft.dll");
Boolean kill = false;
Boolean debug = false;
Boolean valid = true;
while (valid && args.Length > 0)
{
switch (args[0])
{
case "-kill":
kill = true;
args = args.Skip(1).ToArray();
break;
case "-debug":
debug = true;
args = args.Skip(1).ToArray();
break;
default:
valid = false;
break;
}
}
var worldedits = Process.GetProcessesByName("worldedit");
if (worldedits.Count() > 0)
{
if (kill)
{
foreach (var worldedit in worldedits)
worldedit.Kill();
}
else throw new InvalidOperationException("World Editor is already running!" + Environment.NewLine + "You may need to check Task Manager for \"worldedit.exe\", and kill it.");
}
Console.Write("Creating and injecting into World Editor . . . ");
var cmd = '"' + Common.EditorPath + '"';
if (args.Length > 0)
cmd += ' ' + args.Aggregate((a, b) => a + ' ' + b);
Int32 processId;
RemoteHooking.CreateAndInject(Common.EditorPath, cmd, 0, "SharpCraft.dll", "SharpCraft.dll", out processId, PluginContext.Editor, debug, Environment.CurrentDirectory, Common.InstallPath);
Console.WriteLine("Done!");
}
示例7: GetProductOf5Digits
static int GetProductOf5Digits(String s)
{
return s.Aggregate(1, (int prod, char ch) => prod * int.Parse(ch.ToString()));
}
示例8: Dictionary2String
private String Dictionary2String(Dictionary<String, object> dict)
{
String[] tmp = new String[dict.Count];
var q = dict.OrderBy(p => p.Key);
for (int i = 0; i < dict.Count; ++i)
{
tmp[i] = String.Format("{0}={1}", q.ElementAt(i).Key, q.ElementAt(i).Value.ToString());
}
return tmp.Aggregate((s1, s2) => s1 + "&" + s2);
}
示例9: Translite
public static string Translite(String input)
{
return input.Aggregate("", (current, _char) => current + (Char.IsLetter(_char) ? _dict[_char] : _char.ToString()));
}