我最近编写了一个LINQ查询来获取Dictionary包含最近6个月的展示位置金额.
它返回Dictionary月份字符串 - 十进制金额对.
这似乎是一种喧嚣.你们中的任何一位LINQ大师都能帮助我重构这个以使它更干净一点吗?
/// <summary>
/// Gets the last 6 months of Placement History totalled by Month
/// for all Agencies
/// </summary>
/// <returns></returns>
public Dictionary<string, decimal> getRecentPlacementHistory()
{
var placementHistoryByMonth = new Dictionary<string, decimal>();
using (DemoLinqDataContext db = new DemoLinqDataContext())
{
for (int i = 0; i < 6; i++)
{
Decimal monthTotal =
(from a in db.Accounts
where
(a.Date_Assigned.Value.Month == DateTime.Now.AddMonths(-i).Month &&
a.Date_Assigned.Value.Year == DateTime.Now.AddMonths(-i).Month)
select a.Amount_Assigned).Sum();
String currentMonth = DateTime.Now.AddMonths(-i).ToString("MMM"); …Run Code Online (Sandbox Code Playgroud) 例如,如果我这样做:
SELECT * FROM Users WHERE UserId BETWEEN 100 AND 1
Run Code Online (Sandbox Code Playgroud)
会有什么结果?
编辑:对不起,你说得对,我应该指定.我不想知道返回的确切行数,我只是想知道它是否会返回介于1和100之间的行,或者它是否会将行返回min(UserId)到1和100之间max(UserId).
我有一个使用多线程的模块.我想在模块中web.config存储模块创建的线程数.
我应该使用什么标签?
这是一个奇怪的,但希望有人可以在这里给我一个想法.我把几个值到会话中Session_Start的Global.asax我的应用程序.Session_Start我的基页OnInit被调用后立即尝试使用其中一个Session变量.
奇怪的部分有时它是有效的,然后在没有任何变化后会开始给我这个错误:
"时才能使用会话状态
enableSessionState被设定为true,无论是在配置文件或Page指令.还请确保System.Web.SessionStateModule或自定义会话状态模块包含在<configuration>\<system.web>\<httpModules>应用程序中的配置部分."
我看起来并且看起来在启用会话中找到所有不同的方式web.config.这是现在的样子:
<system.web>
...
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"/>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpHandlers>
<xhtmlConformance mode="Legacy"/>
<pages>
<!-- enableSessionState="true" …Run Code Online (Sandbox Code Playgroud) 我有一个问题,而转换为字符串,其值是dd.mm.yyyy要DateTime在C#
string OriginalDateFormat = "28.06.2009";
DateTime dt= Convert.ToDateTime(OriginalDateFormat);
Run Code Online (Sandbox Code Playgroud)
抛出异常 "String was not recognized as a valid DateTime."
但如果它在mm.dd.yyyy那时它运行良好.
我用Google搜索并获得了很多网站,但都是徒劳的
任何的想法?
提前致谢.
我如何转换字符串:
"Microsoft Windows XP Professional x64 Edition|C:\\WINDOWS|\\Device\\Harddisk4\\Partition1"
至
"Microsoft Windows XP Professional x64 Edition"
...使用正则表达式?
我想在|符号后删除所有符号.通过它很容易实现Regex.Replace吗?我在哪里可以找到Regex.Replace模式的语法描述?
在以下代码中,如何识别引发Click事件的控件?
void x_Click(object sender, EventArgs e)
{
//How do I identify the sender?
}
private void fill()
{
for(blah)
{
Button x = new Button();
x.Click += new EventHandler(x_Click);
this.controls.Add(x)
}
}
Run Code Online (Sandbox Code Playgroud) 你知道为什么这个程序没有列出某些文件,即使它们是"常规"的吗?:
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <dirent.h>
int main(void) {
DIR *dh = opendir("./"); // directory handle
struct dirent *file; // a 'directory entity' AKA file
struct stat info; // info about the file.
while (file = readdir(dh)) {
stat(file->d_name, &info);
printf("note: file->d_name => %s\n", file->d_name);
printf("note: info.st_mode => %i\n", info.st_mode);
if (S_ISREG(info.st_mode))
printf("REGULAR FILE FOUND! %s\n", file->d_name);
}
closedir(dh);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
执行完这个程序后,我得到了这个:
note: file->d_name => .
note: info.st_mode => 16877
note: file->d_name => .. …Run Code Online (Sandbox Code Playgroud) 我正在尝试从FTP服务器检索文件列表,但我得到了一些奇怪的非ASCII响应.
这是我正在使用的代码:
public string[] getFileList(string mask)
{
if(!logined)
{
login();
}
Socket cSocket = createDataSocket();
this.getSslDataStream(cSocket);
sendCommand("PASV");
sendCommand("LIST " + "*"+mask);
stream2.AuthenticateAsClient(remoteHost,
null,
System.Security.Authentication.SslProtocols.Ssl3 |
System.Security.Authentication.SslProtocols.Tls,
true);
if(!(retValue == 150 || retValue == 125))
{
throw new IOException(reply.Substring(4));
}
StringBuilder mes = new StringBuilder();
while(true)
{
int bytes = cSocket.Receive(buffer, buffer.Length, 0);
mes.Append(ASCII.GetString(buffer, 0, bytes));
if(bytes < buffer.Length)
{
break;
}
}
string[] seperator = {"\r\n"};
string[] mess = mes.ToString().Split(seperator, StringSplitOptions.RemoveEmptyEntries);
cSocket.Close();
readReply();
if(retValue != 226)
{
throw new IOException(reply.Substring(4)); …Run Code Online (Sandbox Code Playgroud) 我有一个以下格式的DNA文件:
>gi|5524211|gb|AAD44166.1| cytochrome
ACCAGAGCGGCACAGCAGCGACATCAGCACTAGCACTAGCATCAGCATCAGCATCAGC
CTACATCATCACAGCAGCATCAGCATCGACATCAGCATCAGCATCAGCATCGACGACT
ACACCCCCCCCGGTGTGTGTGGGGGGTTAAAAATGATGAGTGATGAGTGAGTTGTGTG
CTACATCATCACAGCAGCATCAGCATCGACATCAGCATCAGCATCAGCATCGACGACT
TTCTATCATCATTCGGCGGGGGGATATATTATAGCGCGCGATTATTGCGCAGTCTACG
TCATCGACTACGATCAGCATCAGCATCAGCATCAGCATCGACTAGCATCAGCTACGAC
Run Code Online (Sandbox Code Playgroud)
如何读取此文件并提取DNA序列部分(ACCAGAGCGG...)而不添加任何换行符,例如:
ACCAGAGCGGCACAGCAGCGACATCAGCACTAGCACTAGCATCAGCATCAGCATCAGCCTACATCATCACAGCAGCATCA
Run Code Online (Sandbox Code Playgroud)
也许不需要正则表达式?