我正在尝试使用以下代码从单词数组中获取不同的单词列表:
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'的两次出现,但它会返回一个短语中每个单词的列表.
有人可以建议我如何获得一个明确的清单?谢谢
戴夫
我在生产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,这不是一个真正的选择.这是什么意思?我该怎样预防呢?
我正在寻找为我正在做的网页创建动态可缩放的线图.
我被告知要" 让它像谷歌一样 "(虽然由一个销售人员反过来鹦鹉客户,所以他的目标很高.一旦我告诉他多少钱,他们都会回到地球上!)
有人可以推荐从哪里开始吗?那里有可用的jQuery插件吗?或者其他产生类似东西的方法?
我可以<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) 我在WPF窗口中有一个图像.当我调整窗口大小时,图像会随之调整大小.在调整图像大小时是否可以保留纵横比,如果窗口太窄,它看起来不会被压扁?如果是这样,怎么样?
几分钟前,当我试图在我的一个控制器中重载一个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)
它工作,但我的代码有点难看!
有什么意见或建议吗?我是否必须在控制器上忍受这种瑕疵?
谢谢
戴夫
我想知道是否有可能创建一个具有类似于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) 我从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>标签.这是我必须使用的东西吗?
目前,当尝试在带有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# ×5
asp.net-mvc ×3
.net ×1
action ×1
actionmethod ×1
app-config ×1
asp.net ×1
c ×1
charts ×1
controller ×1
distinct ×1
image ×1
jquery ×1
linegraph ×1
linq ×1
nhibernate ×1
nullable ×1
out ×1
return-type ×1
wpf ×1
xaml ×1
xhtml ×1
xml ×1