小编Dav*_*Dev的帖子

使用LINQ从数组中选择不同的单词列表

我正在尝试使用以下代码从单词数组中获取不同的单词列表:

string words = "this is a this b";

var split = words.Split(' ');

IEnumerable<Word> distinctWords = (from w in split
                          select new Word
                                     {
                                         Text = w.ToString()
                                     }
                         ).Distinct().ToList();
Run Code Online (Sandbox Code Playgroud)

我认为这会消除'this'的两次出现,但它会返回一个短语中每个单词的列表.

有人可以建议我如何获得一个明确的清单?谢谢

戴夫

c# linq distinct

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

NHibernate LazyInitializationException ..如何预防?

我在生产Web服务器上收到以下错误:

NHibernate.LazyInitializationException
: 
Initializing[Domain.Entities.AudienceTypes.Region#4]-failed to lazily initialize a 
collection of role: Domain.Entities.AudienceTypes.Region.PeerGroups, 
no session or session was closed
Run Code Online (Sandbox Code Playgroud)

这不好.让应用程序再次运行的唯一方法是重置IIS,这不是一个真正的选择.这是什么意思?我该怎样预防呢?

nhibernate

10
推荐指数
2
解决办法
2万
查看次数

如何创建像Google财经这样的动态折线图?

我正在寻找为我正在做的网页创建动态可缩放的线图.

我被告知要" 让它像谷歌一样 "(虽然由一个销售人员反过来鹦鹉客户,所以他的目标很高.一旦我告诉他多少钱,他们都会回到地球上!)

有人可以推荐从哪里开始吗?那里有可用的jQuery插件吗?或者其他产生类似东西的方法?

jquery charts linegraph

10
推荐指数
1
解决办法
2万
查看次数

<appSettings />是否可以包含设置并引用另一个文件中的另一个<appSettings />部分?

我可以<appSettings />在app.config中有一个包含许多设置的<appSettings />部分,但是它也引用了不同文件中的部分吗?

这将允许我保留只有开发人员应该感兴趣的配置选项,例如在主窗口上显示调试输出的选项(非常混乱但对我有用)或将某些文件保存到特定位置.

具体来说,这就是我想要实现的目标:

<!-- this is the appSettings section of the normal app.config file,
     which also contains everything else that app.config would -->
<appSettings configSource="AppSettings.config"> <!-- references another file -->
  <add key="deployment_config_option1" value="1"/>
  <add key="deployment_config_option2" value="2"/>
</appSettings>

<!-- this a new appSettings section of another file called DevSettings.Config
     which only contains settings us developers are interested in
     by keeping these settings in a different file, 
     I can ensure it's never deployed -->
<appSettings> <!-- …
Run Code Online (Sandbox Code Playgroud)

.net app-config visual-studio-2010

10
推荐指数
1
解决办法
2929
查看次数

如何在WPF中强制图像保持纵横比?

我在WPF窗口中有一个图像.当我调整窗口大小时,图像会随之调整大小.在调整图像大小时是否可以保留纵横比,如果窗口太窄,它看起来不会被压扁?如果是这样,怎么样?

wpf xaml image

10
推荐指数
1
解决办法
1万
查看次数

重载控制器操作

几分钟前,当我试图在我的一个控制器中重载一个Action时,我有点意外

我有

public ActionResult Get()
{
    return PartialView(/*return all things*/);
}
Run Code Online (Sandbox Code Playgroud)

我补充道

public ActionResult Get(int id)
{
    return PartialView(/*return 1 thing*/);
}
Run Code Online (Sandbox Code Playgroud)

......突然之间都没有工作

我通过使'id'可以为空并解除其他两种方法来解决这个问题

public ActionResult Get(int? id)
{
    if (id.HasValue)
        return PartialView(/*return 1 thing*/);
    else
        return PartialView(/*return everything*/);
}
Run Code Online (Sandbox Code Playgroud)

它工作,但我的代码有点难看!

有什么意见或建议吗?我是否必须在控制器上忍受这种瑕疵?

谢谢

戴夫

c# asp.net-mvc action controller nullable

9
推荐指数
1
解决办法
1340
查看次数

创建扩展方法以生成打开和关闭标记,如Html.BeginForm()

我想知道是否有可能创建一个具有类似于Html.BeginForm()的功能和行为的扩展方法,因为它会生成一个完整的Html标记,我可以在<% { & } %>标记内具体说明其内容.

例如,我可以有一个视图:

<% using(Html.BeginDiv("divId")) %>
<% { %>
    <!-- Form content goes here -->
<% } %>
Run Code Online (Sandbox Code Playgroud)

在我尝试使用此问题中的示例生成的功能的上下文中,此功能非常有用

这将使我能够为我将要的类型创建容器

<% var myType = new MyType(123, 234); %>
<% var tag = new TagBuilder("div"); %>

<% using(Html.BeginDiv<MyType>(myType, tag) %>
<% { %>
    <!-- controls used for the configuration of MyType  -->
    <!-- represented in the context of a HTML element, e.g.:  -->

    <div class="MyType" prop1="123" prop2="234">
        <!-- add a select here -->
        <!-- …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc xhtml extension-methods html.beginform

9
推荐指数
1
解决办法
1496
查看次数


如何在ASP.NET中将原始XML写入Label

我从Web服务中获取了一块XML.客户端希望在页面上的标签中看到此原始XML.当我尝试这个:

lblXmlReturned.Text = returnedXml;
Run Code Online (Sandbox Code Playgroud)

只显示文本,没有任何XML标记.我需要包含从Web服务返回的所有内容.

这是返回的XML的精简样本:

<Result Matches="1">
    <VehicleData>
        <Make>Volkswagen</Make>
        <UK_History>false</UK_History>
    </VehicleData>
    <ABI>
        <ABI_Code></ABI_Code>
        <Advisory_Insurance_Group></Advisory_Insurance_Group>
    </ABI>
    <Risk_Indicators>       
        <Change_In_Colour>false</Change_In_Colour>
    </Risk_Indicators>
    <Valuation>
        <Value xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></Value>
    </Valuation>
    <NCAP>
        <Pre_2009></Pre_2009>
    </NCAP>
</Result>
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能让它出现在屏幕上?我注意到Stack Overflow在将XML放在scren上做得非常好.我查看了源代码并使用了<pre>标签.这是我必须使用的东西吗?

c xml asp.net

9
推荐指数
2
解决办法
4790
查看次数

为什么out参数不能有默认值?

目前,当尝试在带有out参数的方法中执行某些操作时,我需要在方法体中指定out参数的值,例如

public static void TryDoSomething(int value, out bool itWorkerd)
{
    itWorkerd = true;

    if (someFavourableCondition)
    {
        // if I didn't assign itWorked variable before this point, 
        // I get an error: "Parameter itWorked must be assigned upon exit.
        return;
    }

    // try to do thing

    itWorkerd = // success of attempt to do thing
}
Run Code Online (Sandbox Code Playgroud)

我希望能够设置itWorked参数的默认值,所以我不必在方法体中任意设置值.

public static void TryDoSomething(int value, out bool itWorkerd = true)
{
    if (someFavourableCondition)
    {
        // itWorked was already assigned with a default …
Run Code Online (Sandbox Code Playgroud)

c# out default-value

9
推荐指数
1
解决办法
9497
查看次数