有人可以帮助我进行以下 linq 查询吗?
var userList = _context.Employee.AsQueryable();
var id = 1;
userList = userList
.Join(_context.EmployeePermission,
ul => ul.EmployeeId,
p => p.EmployeeId,
(userlist, perm) => new { Employee = userList, Permisson = perm })
.Where(empAndPerm => empAndPerm.Permisson.Trading >= 1 && empAndPerm.Permisson.EmployeeId == id)
.Select(x => x.Employee);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误;
Cannot implicitly convert type
'System.Linq.IQueryable<System.Linq.IQueryable<Models.Employee>>' to
'System.Linq.IQueryable<Models.Employee>'. Are you missing a cast?
Run Code Online (Sandbox Code Playgroud)
如何解决?
我正在寻找将字符串转换为BASE62的c#代码,如下所示:
http://www.molengo.com/base62/title/base62-encoder-decoder
我需要那些用于URL编码的编码和解码方法.
这可能是造成这种不同行为的原因:
int temp = 2147483647;
Console.WriteLine(temp + 1); //returns -2147483648
List<int> ltemp = new List<int>() { 2147483647, 1 };
Console.WriteLine(ltemp.Sum()); //returns OverFlowException
Run Code Online (Sandbox Code Playgroud) 我有一个C#类,看起来像这样:
public class Model
{
public string title;
public string name;
...
}
Run Code Online (Sandbox Code Playgroud)
某处我有一个变量,其中包含我需要设置的属性"title".我的C#相当生疏,但基本上我想做的是:
var attrToBeSet = "title";
var model = new Model();
model[attrToBeSet] = "someValue";
Run Code Online (Sandbox Code Playgroud)
显然这是伪代码但是......这是否可能与C#一起使用?
我知道那里有很多这样的问题.但我真的找不到任何解决我问题的方法.
我想检查字符串是否包含特定的输入数字.请参阅以下示例:
public Boolean checkString()
{
string input = "2.5.8.12.30";
string intToFind = "3";
if (input.contains(intToFind))
{
return true;
}
else
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
这返回true但我希望它返回false,因为intToFind字符串是3而不是30.所以它是contains()就是问题.
如何让它仅搜索3?
您好,感谢您阅读此帖.
我有一个以这种方式创建的列表
List<Tuple<int, double>> Ratings = new List<Tuple<int, double>>();
Run Code Online (Sandbox Code Playgroud)
让我们说清单的价值如下
Index int double
[0] 1 4,5
[1] 4 1,0
[2] 3 5,0
[3] 2 2,5
Run Code Online (Sandbox Code Playgroud)
如何对列表进行排序,以便最高的双值?像这样
Index int double
[0] 3 5,0
[1] 1 4,5
[2] 2 2,5
[3] 4 1,0
Run Code Online (Sandbox Code Playgroud) 我正在使用string.Join()分隔符连接值 - 这是我使用User类的简化示例:
public class User
{
public string Name { get; set; }
public int Age { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的结果:
User uItem = new User() { Age = 10, Name = null };
string item1 = string.Join(";", string.Empty, 1); // returns ";1"
string item2 = string.Join(";", null, 1); // returns ""
string item3 = string.Join(";", uItem.Name, uItem.Age, 1); // returns ""
string item4 = string.Join(";", 1, null); //returns "1;"
string item5 = string.Join(";", …Run Code Online (Sandbox Code Playgroud) 我正在尝试<T>使用冒泡排序对类型列表进行排序.不幸的是我在比较未知类型的对象时遇到了问题.
到目前为止我尝试过的:
public static void BubbleSort<T>(this List<T> array)
{
for (int i = (array.Count - 1); i >= 0; i--)
{
for (int j = 1; j <= i; j++)
{
if (array[j - 1] > array[j]) // issue here
{
var temp = array[j - 1];
array[j - 1] = array[j];
array[j] = temp;
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 为什么该方法AwakeTest需要3秒而不是1秒
public static async void AwakeTest()
{
var Do1 = Sleep(1, 1);
var Do2 = Sleep(1, 2);
var Do3 = Sleep(1, 3);
await System.Threading.Tasks.Task.WhenAll(Do1, Do2, Do3);
Console.WriteLine(await Do1);
Console.WriteLine(await Do2);
Console.WriteLine(await Do3);
}
private static async System.Threading.Tasks.Task<int> Sleep(int Seconds, int ID)
{
if (Seconds < 0)
{
throw new Exception();
}
System.Threading.Thread.Sleep(Seconds * 1000);
return ID;
}
Run Code Online (Sandbox Code Playgroud) 我有一个数据列表集合,例如:
List<String> Dummy = new List<String>()
{
"1001A",
"1003A",
"1002B",
"1002A",
"1003B",
"1001B",
"1003C",
"1002C",
"1001C",
};
Run Code Online (Sandbox Code Playgroud)
我想把这个数据列表整理成一系列.主要系列将重点关注Alphabet(字符串的最后一个字符),子系列将基于左边的数字.输出将是这样的:
1001A
1002A
1003A
1001B
1002B
1003B
1001C
1002C
1003C
Run Code Online (Sandbox Code Playgroud)
除了上面的示例之外,我已经只有一系列数字的功能代码.感谢阅读我的帖子.