小编Abd*_*tef的帖子

Linq - 包含的顺序

我有一种情况,需要为 Include 对象完成 OrderBy。这是我迄今为止尝试过的方式

Customers query = null;

try
{
    query = _context.Customers
        .Include(x => x.CustomerStatus)
        .ThenInclude(x => x.StatusNavigation)
        .Select(x => new Customers()
        {
            Id = x.Id,
            Address = x.Address,
            Contact = x.Contact,
            Name = x.Name,
            CustomerStatus = new List<CustomerStatus>
            {
                x.CustomerStatus.OrderByDescending(y => y.Date).FirstOrDefault()
            }
        })
        .FirstOrDefault(x => x.Id == 3);
}
catch (Exception ex)
{
    throw;
}
Run Code Online (Sandbox Code Playgroud)

上面的代码成功地对 include 元素进行了排序,但不包括它的子表。例如:客户包括 CustomerStatus 但 CustomerStatus 不包括 StatusNavigation 表。

我什至尝试过这个,但它都不能帮助我

_context.Customers
    .Include(x => x.CustomerStatus.OrderByDescending(y => y.Date).FirstOrDefault())
    .ThenInclude(x => x.StatusNavigation).FirstOrDefault(x => x.Id == …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework asp.net-core

4
推荐指数
2
解决办法
690
查看次数

C布尔逻辑

我一直在尝试使用C语言编写一些程序并且遇到这个......

#include<stdio.h>
int main()
{
    int j = 3, k;
    k= !5 && j;
    printf("%d", k);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以弄清楚这是什么问题,如果我编译程序,我会得到0

当我在c#中尝试相同的代码

public void logic()
{
    j = 5;
    k = !4 && j;
    Console.WriteLine("hence the value would be " + k);
}
Run Code Online (Sandbox Code Playgroud)

这将生成错误*(错误1运算符'!'不能应用于'int'类型的操作数C:\ Documents and Settings\SANDEEP\My Documents\Visual Studio 2005\Projects\ConsoleApplication18\ConsoleApplication18\Program.cs 21 17 ConsoleApplication18)

我想知道为什么我的c代码的输出不起作用,我怎么能使用!运营商在c#..... plz帮助....

c c# boolean-logic

3
推荐指数
2
解决办法
1814
查看次数

Optimize C# code for counting number of occurences in nested loop

I want to optimize this code for counting the number of occurrences in a list of strings. To be specific, I have two lists

1) cat: a huge list of string with duplicates (duplicates must exist).

2) cat_unq: the distinct elements from cat.

What I am currently doing in my code is looping all unique elements in cat_unq and counting how many times the unique element exists in the list of duplicates. The search runs on a mobile …

c# optimization

3
推荐指数
1
解决办法
63
查看次数

pow 在 CUDA 中的 __device__ 函数内无法正常工作

我正在尝试使用 Visual Studio 2019 在 CUDA 中的函数pow内部使用函数。__device__

__device__ double Len(double a, double b)
{
    return pow(a, 2) + pow(b, 2);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试构建解决方案时,它一直给我这个错误。

错误“x64/Debug/kernel.cu.obj”中对“_Z3powdi”的未定义引用

2仅当我更改为时它才有效2.0。我认为这可能是使用非整数值作为参数的函数的正确格式,但是当我在正常的C++代码中尝试它时,它可以正常使用 integer 2

出现这个问题的原因是什么?我该如何解决这个问题?

笔记:

  1. 前几天还正常,这个错误可能是在最新更新Visual Studio 2019版本16.8.0之后发生的。
  2. 我尝试添加#include <math.h>和删除它,但它给出了相同的错误。

c++ cuda pow

3
推荐指数
1
解决办法
2046
查看次数

如何在列表中按值保存数组而不是C#中的引用

我想保存我当前的数组状态,然后更改该数组但是当我在列表中保存我的数组然后更改我的数组时,列表中的数组也会更改,这是示例代码,这是我的代码的一部分:

void main()
{
    List<int[]> lisarr = new List<int[]>();
    int[] a = new int[1];
    a[0] = 1;
    lisarr.Add(a);
    a[0] = 10;
    // at this time lisarr[0] also changes
   ....
}
Run Code Online (Sandbox Code Playgroud)

如果您跟踪此代码,请注意我的列表中的数组也会更改,但我不想这样,我该如何解决此问题?

c# arrays list

2
推荐指数
1
解决办法
2673
查看次数

如何放大鼠标光标下的点(处理)

我想放大处理草图中鼠标光标下的点.问题的规模部分非常简单; 这是我无法弄清楚的翻译部分.我们的想法是能够放大到Processing草图,同时保持草图中对象之间的相对距离.

任何帮助将不胜感激.放大但不保持相对距离的基本草图如下:

float scaleFactor;
void setup()
{
    size(300, 300);
    scaleFactor = 1;
}

void draw()
{
    background(255);
    fill(128);
    noStroke();
    pushMatrix();
    scale(scaleFactor);
    rect(0, 0, 100, 100);
    popMatrix();
}

void keyPressed()
{
    if (key == 'r')
    {
        scaleFactor = 1;
    }
}

void mouseWheel(MouseEvent e)
{
    scaleFactor += e.getAmount() / 100;
}
Run Code Online (Sandbox Code Playgroud)

processing

2
推荐指数
1
解决办法
3855
查看次数

捕捞后无法退还布尔

我试图false在方法中捕获异常的情况下返回值,但是,它似乎是在返回异常而不是布尔值。

我用它来调用第一个方法:

try
{
    bool wasImported = WriteAddress(theCompany.CompanyId, company);
    if(wasImported == false)
    {
        ///some logic here
    }
}
catch(Exception ex)
{
    string msg = ex.Message;
}
Run Code Online (Sandbox Code Playgroud)

这里是WriteAddress方法:

private bool WriteAddress(Guid companyId, ModuleView.CompanyBO company)
{
    try
    {
        if (company.First_Address != "" || company.First_Address2 != "" || company.First_City != "" || company.First_State != "" || company.First_Zip != "")
        {
            bool isDate = false; 
            DateTime thisDate;
            ModuleView.AddressBO theAddress = new ModuleView.AddressBO();
            theAddress.CompanyId = companyId;
            // theAddress.Address = Conversions.Truncate(company.First_Address,200);
            theAddress.Address …
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
273
查看次数

参数化抽象类构造函数

我有一个类似下面的课程

public abstract class ABC
{
    int _a;
    public ABC(int a)
    {
        _a = a;
    }
    public abstract void computeA();
};
Run Code Online (Sandbox Code Playgroud)

派生类是否必须为base/abstract类构造函数提供参数?有没有办法在不提供参数的情况下初始化派生类?

提前致谢,

约翰

c# constructor abstract-class

1
推荐指数
1
解决办法
1万
查看次数

需要两次尝试才能打破我的while循环

我正在做Udemy课程,并试图完成一个练习,要求用户输入数字,或者如果我写“ quit”,则中断循环。循环后,我必须对所有数字求和。

我几乎可以正常工作了,但是我不得不写两次 “退出” 才能使其崩溃,但我不明白为什么。感谢任何帮助

int[] total = new int[10];
int number;
int counter = 0;
Console.WriteLine("Write up to 10 number or 'quit' to exit early");
while (counter < 10)
{
    bool success = int.TryParse(Console.ReadLine(), out number);
    if (success == true)
    {
        total[counter] = number;
        counter++;
    } else if (Console.ReadLine() == "quit")
    {
        break;
    } else
    {
        Console.WriteLine("Wrong input.");
    }
}
int sum = total.Sum();
Console.WriteLine("The sum is {0}", sum);
Run Code Online (Sandbox Code Playgroud)

c# tryparse while-loop

1
推荐指数
1
解决办法
84
查看次数

这段代码如何在碱基之间转换?

#include<stdio.h>
#include<string.h>
void baseconversion(char s[20], int, int);
main()
{   
    char s[20];
    int base1, base2;
    printf("Enter the number and base:");
    scanf("%s%d", s, &base1);
    printf("Enter the base to be converted:");
    scanf("%d", &base2);
    baseconversion(s, base1, base2);
}

void baseconversion(char s[20], int b1, int b2)
{
    int count = 0, r, digit, i, n = 0, b = 1;
    for(i = strlen(s) - 1; i >= 0; i--)
    {
        if(s[i] >= 'A' && s[i] <= 'Z')
        {
            digit = s[i] - '0' - 7; …
Run Code Online (Sandbox Code Playgroud)

c converters

1
推荐指数
1
解决办法
57
查看次数