平台C#,Dot net 4.0
var city0 = DataCache.GetAllCities().Where(c => c.GeoName.Contains("Dubai")).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
变量Duabi存在于数据中,它返回城市对象
var city1 = DataCache.GetAllCities().Where(c => c.CityID== 23804982) .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
数据中不存在id 23804982,这将返回null对象
var city2 = DataCache.GetAllCities().Where(c => c.GeoName.Contains("WrongCityName")).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
变量WrongCityName 在数据中不存在,这将返回以下错误.
你调用的对象是空的.
[编辑]我在上次执行查询时收到错误.不是在我评估city2时
我的代码看起来很难看,而且我知道必须有更好的方法来做我正在做的事情:
private delegate string doStuff(
PasswordEncrypter encrypter, RSAPublicKey publicKey,
string privateKey, out string salt
);
private bool tryEncryptPassword(
doStuff encryptPassword,
out string errorMessage
)
{
...get some variables...
string encryptedPassword = encryptPassword(encrypter, publicKey,
privateKey, out salt);
...
}
Run Code Online (Sandbox Code Playgroud)
到目前为止这个东西并没有打扰我.这就是我打电话tryEncryptPassword看起来如此丑陋,并且有重复,因为我用两种方法调用它:
public bool method1(out string errorMessage)
{
string rawPassword = "foo";
return tryEncryptPassword(
(PasswordEncrypter encrypter, RSAPublicKey publicKey,
string privateKey, out string salt) =>
encrypter.EncryptPasswordAndDoStuff( // Overload 1
rawPassword, publicKey, privateKey, out salt
),
out errorMessage
);
}
public bool method2(SecureString …Run Code Online (Sandbox Code Playgroud) 是否有任何tweek使用IN像lambda中的查询?例如,我有一个查询
Select * from Users where Id in ( 1,45,67, 89)
Run Code Online (Sandbox Code Playgroud)
我可以用linq写同样的东西吗?例如,我有用户说的列表
List<Users> oUserList= new List<Users>();
Run Code Online (Sandbox Code Playgroud)
我有int列表
List<Int32> Ids
Run Code Online (Sandbox Code Playgroud)
我想写一下查询
var data= select all users from 'oUserList' where id not in 'Ids'
Run Code Online (Sandbox Code Playgroud)
谁能告诉我怎么写这个?
谢谢
问题解决了
var data = oUserInfolist.Where(x => (!oo.Contains(x.ID)));
Run Code Online (Sandbox Code Playgroud) 鉴于:
string removeRows = "";
int i = 0;
foreach (var row in userStats)
{
if (row.OrderRow.RegistrationType == "Want Removed")
{
removeRows = removeRows + i.ToString() + ",";
}
i++;
}
Run Code Online (Sandbox Code Playgroud)
什么是Lambda语法来执行删除?
如何编写lambda表达式以获取具有description ="PickMe"或"TakeMe"的详细行的所有订单

如何使用Lambda表达式编写此linq查询
public List<Employee> GetList()
{
return (from c in DALContext.MST
select new Employee(ID=c.CD, Name=c.NAME)).ToList();
}
Run Code Online (Sandbox Code Playgroud) 我有一个List<string>,我想迭代这个集合,并在按钮点击时对每个字符串做一些事情.我在这里有一个小例子来说明我正在尝试做的事情:
//items is a System.Collections.Generic.List<string>
foreach (string s in items)
{
Button b = new Button() { Content = s };
b.Click += (obj, ev) =>
{
MessageBox.Show(s);
}
//add b to form, container, etc...
}
Run Code Online (Sandbox Code Playgroud)
正如您所期望的那样,按钮是使用正确的内容正确创建的,但是当我单击任何按钮时,其中的文本MessageBox始终是最后一个字符串items.我错过了什么?为什么Click按钮的所有功能都传递给集合中的最后一项?
我有一个构建版本列表
List<int[]> BuildVersions;
Run Code Online (Sandbox Code Playgroud)
我怎样才能找到最后的构建版本.
构建诸如的版本
100.1.2.3
101.12.3.2
101.12.3.3
Run Code Online (Sandbox Code Playgroud)
更新:表达式必须先检查第一个数字,然后检查第二个数字,然后检查第三个数字,然后检
如何使用lambda表达式从List中获取名称等于"john"的人数.我怎样才能创建我的lambda表达式?
List<Persons> persons;
person.Where(p=>p.Name.Equals("John");
Run Code Online (Sandbox Code Playgroud)
现在我要对返回的列表进行计数还是应该嵌套它?
lambda ×10
c# ×7
linq ×3
asp.net ×2
.net ×1
.net-4.0 ×1
delegates ×1
linq-to-sql ×1
refactoring ×1
silverlight ×1