小编DVL*_*DVL的帖子

Asp.Net MVC我的代码出了什么问题?

我有一个函数叫做getWords(int wrNum)wich从数据库中使用实体框架返回wrNum数字随机数,当wrNum为300时,这个函数需要花费10秒的时间.我不明白为什么需要这么多时间.请帮助我的代码出了什么问题?

public List<string> getWords(int wrNum)
{
    IDVLTest d3 = new DVLTest();
    for (int i = 0; i < wrNum;i++ )
    {
        string word = d3.getRandomWord().Text;
        Words.Add(new WordView { Word = word, Status = WordStatus.Right });
    }
    return Words.Select(w=>w.Word).ToList();
}

public class DVLTest:IDVLTest
{
...
    public Word getRandomWord()
    {
        Random r = new Random();
        int i = r.Next(DVL_Entitie.Words.Count());
        return DVL_Entitie.Words.ToList().ElementAt(i);
    }
...
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc entity-framework entity-framework-6

3
推荐指数
1
解决办法
122
查看次数

我可以在linq中实现属性而不调用方法两次吗?

我在C#中有这种代码,如果有更好的计算Name属性的解决方案,我很有意思:

dictItem.valueElement.Select(li => new ItemWithNameAndUrl {
    Name = StringParser.getBeforeString("(", li.InnerText) == string.Empty ?
        li.InnerText : StringParser.getBeforeString("(", li.InnerText), //don't like it
    Url = li.Element("a").Attributes["href"].Value
}).ToList());
Run Code Online (Sandbox Code Playgroud)

有没有办法不StringParser.getBeforeStringName属性调用方法两次?

c# linq

3
推荐指数
1
解决办法
64
查看次数

以c#方式重复获取一个字符串的字符串

我想要这样简单的功能:

string getStringWithCharAndLength(char ch, int l)
{
  //Some easy code
  //return ch+ch+...+ch(string with Length l)
}
Run Code Online (Sandbox Code Playgroud)

例:

string str = getStringWithCharAndLength('k',5);<br>
Console.WriteLine(str);// "kkkkk"
Run Code Online (Sandbox Code Playgroud)

注意:不是这种解决方案:

string getStringWithCharAndLength(char ch, int l)
{
   string str="";
   for(int i=0;i<l;i++)
      str+=ch;
   return str;
}
Run Code Online (Sandbox Code Playgroud)

c#

-1
推荐指数
2
解决办法
135
查看次数