我对LINQ很新.
假设我有下表:
Incident
ID DeviceID Time Info
1 1 5/2/2009 d
2 2 5/3/2009 c
3 2 5/4/2009 b
4 1 5/5/2009 a
Run Code Online (Sandbox Code Playgroud)
在LINQ中,我如何编写查找最新且不同(在设备ID上)事件集的查询?我想要的结果是:
ID DeviceID Time Info
3 2 5/4/2009 b
4 1 5/5/2009 a
Run Code Online (Sandbox Code Playgroud)
您是否必须创建IEqualityComparer来执行此操作?
我在使用ASP.NET网站的测试服务器上遇到了一些麻烦.我搞砸了,并且默认网站的主目录指向了错误的位置.当我尝试:
ConfigurationManager.ConnectionStrings["connectionString"];
Run Code Online (Sandbox Code Playgroud)
它返回null,但是
using System.Web.Configuration;
/* ... */
var rootWebConfig =
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
rootWebConfig.ConnectionStrings.ConnectionStrings["connectionString"].ConnectionString;`
Run Code Online (Sandbox Code Playgroud)
返回正确的连接字符串.
这两种方法之间有什么区别?
编辑:我真正要问的是,为什么ConfigurationManager在主目录设置不正确时方法失败,否则成功,并且WebConfigurationManager无论主目录是否正确设置都成功?是否存在其他差异,例如关于访问控制的假设?
c# asp.net configurationmanager behavior webconfigurationmanager
我想从aspx控件调用一个javascript函数.例如,假设我有:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function test(x, y)
{
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click"/>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
并在后面的代码中:
protected void Button1_Click(object sender, EventArgs e)
{
// do stuff (really going to a database to fill x and y)
int[] x = new int[] { 1, 2, 3, 4, 5 };
int[] y = new int[] { 1, 2, 3, 4, 5 };
// call javascript function as …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Windows服务的安装程序,并希望避免使用InstallUtil.exe.安装程序似乎正常工作(可执行文件和dll位于正确的目录中),但该服务未显示在"计算机管理"下.
这是我到目前为止所做的:
服务类名称是默认值 - Service1.
在项目安装程序中,服务安装程序的ServiceName与类名称 - Service1匹配.
在"自定义操作"下,服务的主要输出已添加到"安装","提交","回滚"和"卸载".
我使用http://support.microsoft.com/kb/816169作为参考.
有任何想法吗?
我需要一个开源/免费的C#工具或库,可以为学生项目进行财务图表.它需要能够做一个开 - 高 - 低 - 关闭图表,并能够绘制我计算的各种技术指标,所有这些都来自Windows窗体.
有什么建议?
我正在学习Windows-Installer和Wix,并且有很多与它如何工作有关的问题:
抽象类和只有受保护构造函数的类之间有什么区别?它们似乎与我非常相似,因为你无法实例化任何一个.
编辑:
如何在派生类中创建实例,并使用带有受保护构造函数的基类?例如:
public class ProtectedConstructor
{
protected ProtectedConstructor()
{
}
public static ProtectedConstructor GetInstance()
{
return new ProtectedConstructor(); // this is fine
}
}
public class DerivedClass : ProtectedConstructor
{
public void createInstance()
{
ProtectedConstructor p = new ProtectedConstructor(); // doesn't compile
}
public static ProtectedConstructor getInstance()
{
return new ProtectedConstructor(); // doesn't compile
}
}
Run Code Online (Sandbox Code Playgroud) 我正在学习WPF动画,并对如何顺序应用动画感到困惑.举个简单的例子,我在一个统一的网格中有四个矩形,并希望按顺序改变每个矩形的颜色.这是我到目前为止所拥有的:
public partial class Window1 : Window
{
Rectangle blueRect;
Rectangle redRect;
Rectangle greenRect;
Rectangle yellowRect;
public Window1()
{
InitializeComponent();
blueRect = new Rectangle() { Fill = System.Windows.Media.Brushes.Blue, Name="Blue"};
redRect = new Rectangle() { Fill = System.Windows.Media.Brushes.Red, Name="Yellow"};
greenRect = new Rectangle() { Fill = System.Windows.Media.Brushes.Green, Name="Green" };
yellowRect = new Rectangle() { Fill = System.Windows.Media.Brushes.Yellow, Name="Yellow" };
UniformGrid1.Children.Add(blueRect);
UniformGrid1.Children.Add(redRect);
UniformGrid1.Children.Add(greenRect);
UniformGrid1.Children.Add(yellowRect);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
animateCell(blueRect, Colors.Blue);
animateCell(redRect, Colors.Red);
}
private void animateCell(Rectangle rectangle, Color …Run Code Online (Sandbox Code Playgroud) 我正在尝试在网络上使用热量.csproj,然后在输出上使用蜡烛.到目前为止,我已经完成了:
heat project "StatusReport Web.csproj" -pog:Binaries pog:Content -ag -out StatusReport.wxs
Run Code Online (Sandbox Code Playgroud)
然后:
candle StatusReport.wxs
Run Code Online (Sandbox Code Playgroud)
但是,根据后者,我得到:
Error CNDL0150: Undefined preprocessor variable '$(var.StatusReport Web.TargetDir)'.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
另外,有没有办法在Visual Studio Wix项目中使用热量输出?
我想知道是否可以在C#中使用表达式作为变量/参数.我想做这样的事情:
int x = 0;
public void g()
{
bool greaterThan = f("x>2");
bool lessThan = f("x<2");
}
public bool f(Expression expression)
{
if(expression)
return true;
else
return false;
}
Run Code Online (Sandbox Code Playgroud)
这是我不想做的事情:
int x = 0;
public void g()
{
bool greaterThan = f(x, '<', 2);
}
public bool f(int x, char c, int y)
{
if(c == '<')
return x < y;
if(c == '>')
return x > y;
}
Run Code Online (Sandbox Code Playgroud)
我真正得到的是一种方法,可以使用每个开关或一系列if语句:<> <=> = ==!=.有办法吗?
编辑:假设表达式是一个字符串,如"x <2".有没有办法从字符串转到谓词而不使用条件上的一系列if语句?
c# ×6
asp.net ×2
wix ×2
.net ×1
animation ×1
behavior ×1
charts ×1
code-behind ×1
constructor ×1
distinct ×1
financial ×1
guid ×1
heat ×1
javascript ×1
linq ×1
msi-patch ×1
preprocessor ×1
protected ×1
sql-order-by ×1
storyboard ×1
winforms ×1
wix3 ×1
wpf ×1