是否可以使用Lambda进行相同的操作
for (int i = 0; i < objEntityCode.Count; i++)
{
options.Attributes[i] = new EntityCodeKey();
options.Attributes[i].EntityCode = objEntityCode[i].EntityCodes;
options.Attributes[i].OrganizationCode = Constants.ORGANIZATION_CODE;
}
Run Code Online (Sandbox Code Playgroud)
我的意思是说使用lambda重写语句.我试过了
Enumerable.Range(0,objEntityCode.Count-1).Foreach(i=> {
options.Attributes[i] = new EntityCodeKey();
options.Attributes[i].EntityCode = objEntityCode[i].EntityCodes;
options.Attributes[i].OrganizationCode = Constants.ORGANIZATION_CODE; }
);
Run Code Online (Sandbox Code Playgroud)
但不工作我正在使用C#3.0
我刚刚发现了两段代码
#if CONSOLE // defined by the console version using
ournamespace.FactoryInitializer;
#endif
Run Code Online (Sandbox Code Playgroud)
和
#if _NET_1_1
log4net.Config.DOMConfigurator.ConfigureAndWatch(new System.IO.FileInfo(s) );
#else
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(s) );
#endif
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我一个正在运行的样本(请提供一个简单的代码片段)这些代码片段的重要性以及何时以及如何使用这些代码片段?
谢谢.
考虑下面的程序
myThread = new Thread(
new ThreadStart(
delegate
{
Method1();
Method2();
}
)
);
Run Code Online (Sandbox Code Playgroud)
是2个线程被并行调用(多任务处理)还是单个线程按顺序调用方法?
这很紧急.
我有以下功能
public static List<DateTime> GetOnlyFridays(DateTime endDate, int weeks, bool isIncludeBaseDate)
{
//Get only the fridays from the date range
List<DateTime> dtlist = new List<DateTime>();
List<DateTime> tempDtlist = (from dtFridays in GetDates(endDate, weeks)
where dtFridays.DayOfWeek == DayOfWeek.Friday
select dtFridays).ToList();
if (isIncludeBaseDate)
{
dtlist = tempDtlist.Skip(1).ToList();
dtlist.Add(endDate);
}
else
{
dtlist = tempDtlist;
}
return dtlist;
}
Run Code Online (Sandbox Code Playgroud)
基本上我正在做的是使用GetDates函数获取日期列表,然后根据isIncludeBaseDate bool value(如果为真)跳过最后一个日期并添加Base Date
它工作正常,但这个程序可以改进吗?
我正在使用C#3.0和Framework 3.5
谢谢