this code
是其中的一部分
NBuilder
. 我今天心情不好……为了证明这一点,我不明白这个(简单的)代码要做什么。
下面是答案,后面是代码。
GetRandom.Phrase(5) == null or et or ut or do or elit or amet..
(nothing over 4 characters)
GetRandom.Phrase(4) == null or sit or sed or do ..
(nothing over 3 characters)
GetRandom.Phrase(3) == null or et or ut or do (nothing over 2 characters)
GetRandom.Phrase(2) == null
GetRandom.Phrase(1) == null
代码…
private static readonly string[] latinWords = { "lorem", "ipsum", "dolor",
"sit", "amet", "consectetur", "adipisicing", "elit", "sed", "do",
"eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore",
"magna", "aliqua" };
public virtual string Phrase(int length)
{
var count = latinWords.Length;
var result = string.Empty;
var done = false;
while (!done)
{
var word = latinWords[Next(0, count - 1)];
if (result.Length + word.Length + 1 > length)
{
done = true;
}
else
{
result += word + " ";
}
}
return result.Trim();
}
我想这个方法应该返回x个短语或至少指定长度的随机短语?