我正在开发一组相当复杂的接口,它允许定义具有特定结构的对象。通过接口和泛型,它还允许我定义每个元素中可用的接口组合。该结构映射了我们背景中的某些内容,因此目标是在代码中重新创建结构,以便更好地理解代码实际操作的内容。
结果如下:
static void Main(string[] args)
{
IComplexDefinition1 CD1 = null;
CD1.Access.Level1.ElementB.SomeStructrueMethod();
CD1.Access.Level1.ElementC.ActorAMethod1();
CD1.Access.Level1.ElementC.ActorBMethod2();
CD1.Access.Level1.ElementC.ActorCMethod1();
CD1.Access.Level2.ElementA.SomeOperationPoolMethod();
CD1.Access.Level2.ElementC.ActorAMethod2();
CD1.Access.Level2.ElementC.ActorBMethod1();
CD1.Access.Level2.ElementC.ActorCMethod2();
}
Run Code Online (Sandbox Code Playgroud)
现在,在实现具体类时,我在 Visual Studio 中单击了“自动实现”,它出现了一行我到目前为止还没有看到的代码(并且没想到会发生这种情况)。因此,我正在寻找它的工作原理以及我可以在哪里阅读/研究更多相关信息的见解。
具体实现的相关部分是:
public class ComplexDefinition : IComplexDefinition1,....
{
protected IActorComposition _actors;
protected SomeStructure _structure;
protected SomeOperationPool _operationPool;
public IElementsBC<IActorCompositionLevel2, SomeStructure> Level1 => this;
public IElementsAC<IActorCompositionLevel1, SomeOperationPool> Level2 => this;
public SomeStructure ElementB => _structure;
public SomeOperationPool ElementA => _operationPool;
public IActorCompositionLevel2 ElementC => _actors;
IActorCompositionLevel1 IElementC<IActorCompositionLevel1>.ElementC => _actors;
}
Run Code Online (Sandbox Code Playgroud)
尤其是这两行让我感到困扰(尤其是最后一行):
public IActorCompositionLevel2 ElementC => _actors;
IActorCompositionLevel1 IElementC<IActorCompositionLevel1>.ElementC …Run Code Online (Sandbox Code Playgroud) 例如,假设我有一个 12 行的 SQL 表,它看起来像下面左边的表,我想在右边创建聚合行数的汇总表。
这是此示例的 SQLFiddle:http ://sqlfiddle.com/#!9/ee508f/1
我可以通过以下查询分别获取这 4 个汇总列中的每一个:
SELECT Product, COUNT(*) AS bad FROM mytable WHERE Quality IN (1,2,3) GROUP BY Product;
SELECT Product, COUNT(*) AS acceptable FROM mytable WHERE Quality IN (4,5,6) GROUP BY Product;
SELECT Product, COUNT(*) AS good FROM mytable WHERE Quality IN (7,8,9) GROUP BY Product;
SELECT Product, COUNT(*) AS great FROM mytable WHERE Quality IN (10) GROUP BY Product;
Run Code Online (Sandbox Code Playgroud)
但是如何将这 4 个结果合并到一个表格中,就像我的图片中显示的那样?我想要一个可以简单地添加额外列(而不是具有另一个嵌套级别)的解决方案,因为在我的实际项目中,我有 12 个这样的列并且深度嵌套,许多查询不会很可读。
我读过的大多数文档都表明,CROSS APPLY 的行为方式与 INNER JOIN 类似,只有在两个源表中都有匹配的行时,行才会包含在输出中。
然而,情况似乎并不总是如此,例如,如果您运行以下 SQL 查询,结果将包含 3 行,其中一行包含许多 NULL,因为右侧表中没有行:
CREATE TABLE #Order
(
Id int PRIMARY KEY
)
CREATE TABLE #OrderItem
(
OrderId int NOT NULL,
Price decimal(18, 2) NOT NULL
)
INSERT INTO #Order
VALUES(1), (2), (3)
INSERT INTO #OrderItem
VALUES(1, 10), (1, 20), (3,100)
SELECT *
FROM #Order o
CROSS APPLY
(
SELECT SUM(Price) AS TotalPrice, COUNT(*) AS Items, MIN(Price) AS MinPrice
FROM #OrderItem
WHERE OrderId = o.Id
) t
DROP TABLE #Order
DROP TABLE …Run Code Online (Sandbox Code Playgroud) SQL 新手,但我试图找到titles“蓝色”和“黑色”字样的位置。但是,它们不能来自 ID 为 1 和 5 的用户。这就是我所做的:
SELECT title, id_card
FROM site
WHERE (title LIKE "%blue%" OR title LIKE "%black%")
AND (id_card != 1 OR id_card != 5)
ORDER BY id_card ASC;
Run Code Online (Sandbox Code Playgroud)
但是,当我添加 id 1 和 id 5 不应该在查询中时,它会显示如下内容:
| 博客标题 | 用户 |
|---|---|
| 今天的蓝天真好 | 1 |
| 黑色是我最喜欢的颜色 | 2 |
| 我感觉很蓝 | 2 |
| 她穿着黑色 | 3 |
但是,当我id_card != 5从代码中擦除时,它工作得很好。
| 博客标题 | 用户 |
|---|---|
| 黑色是我最喜欢的颜色 | 2 |
| 我感觉很蓝 | 2 |
| 她穿着黑色 | 3 |
我只是想知道我哪里出错了以及如何解决这个问题。先感谢您!
在 SQL Server 数据库中,我有一个包含一DateTime列的表,我想获取特定日期的行。
我发现了很多选择,例如:
WHERE myColumn BETWEEN '2020-10-10T00:00:00.00' AND '2020-10-10T23:59:59.999'WHERE CAST(myColumn AS date) = '2020-10-10'WHERE date LIKE '%2020-10-10%'...
其中哪一个最快?
我正在阅读mssqltips上的文章,想尝试正则表达式中的插入符号。我非常了解正则表达式并且经常使用它,尽管在 SQl Server 查询中使用得不多。
对于以下名称列表,我原以为 1) select * from people where name like '%[^m]%;'会返回那些不包含“m”的名称。但事实并非如此。我知道我可以做得到2) select * from people where name not like '%m%';我想要的结果,但我只是困惑为什么 1) 不能按预期工作。
我正在使用 SQL Server 2017,但这里有一个小提琴:
当我使用时
var frontPage = await GetFrontPage();
protected override async Task<WordDocument> GetFrontPage()
{
return null;
}
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常,我在 frontpage 变量中得到空值。但是当我将函数重写为
protected override Task<WordDocument> GetFrontPage() => null;
Run Code Online (Sandbox Code Playgroud)
我收到了一个NullReferenceException.
谁能帮助我理解这两种说法之间的区别?
由于项目需要,需要对C#程序集进行反编译。根据同事的推荐使用 Relector 下面是一个示例:
internal class WebTreeDialogPage : WebXmlHttp2Page
{
public WebTreeDialogPage()
{
this.Source = new EasySearch2DataSet();
base.Style = PageStyle.Custom;
base.Operation = "TreeExpand";
}
protected override void DoPost()
{
base.DoPost();
this.GetXsltFile();
base.Response.ContentEncoding = Encoding.UTF8;
string content = this.Transform.TransformContent(base.IsIe);
if (AppSettings.Current.Debug)
{
FileUtil.SaveFile(AppSettings.Current.XmlPath + "EasySearch.html", content);
}
base.Response.Write(content);
}
}
Run Code Online (Sandbox Code Playgroud)
Decompiled code base.Response.ContentEncoding = Encoding.UTF8
Why is there an error in Encoding.UTF8, suggesting that "string" does not contain the definition of "UTF8".
And there are "Cannot find extension method 'UTF8' that accepts …
我想这样做,如果变量 speedPoints 是一个可以被 10 整除的数字,那么我的变量 moveSpeed 就会增加 1,但是,当我使用 % 运算符来确定 if 语句中的 speedPoints 是否是 10 的倍数时,它给出我的错误CS0029。我可以做什么来修复它?
错误出现在第 26 行,我在其中添加了注释。
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class PipeMoveScript : MonoBehaviour
{
public float moveSpeed = 1;
public float deadZone = -45;
public bird_script bird;
public LogicScript logic;
// Start is called before the first frame update
void Start()
{
bird = GameObject.FindGameObjectWithTag("Bird").GetComponent<bird_script>();
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
}
// Update is called once per frame
void Update()
{
// here …Run Code Online (Sandbox Code Playgroud) 我正在尝试用纯 C# 打开一个窗口。为此,我创建了一个窗口构造函数 ( SGFWindow) ,该窗口构造Window函数从以下位置扩展了该类System.Windows:
namespace SGF
{
public partial class SGFWindow : Window
{
public SGFWindow()
{
this.Title = "SGF Window";
this.Width = 200;
this.Height = 200;
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个WindowTest类来测试它:
namespace SGF
{
public class WindowTest
{
public static void Main(string[] args)
{
SGFWindow window = new SGFWindow();
window.Show();
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,我收到“调用线程必须是 STA,因为许多 UI 组件都需要这个”。错误 ; 只不过这不是一个线程(或者不是我创建的线程?)。
我搜索了它,但它总是关于一个线程,我找不到如何修复这个错误。我也看到过一些东西[STAThread],但显然不适合它。
预先感谢,马索。
我通常使用 C# 编程,但也使用旧语言 Delphi。据我所知,在 Delphi 中,属性使用大量代码,如下所示:
private
FOPPORTUNITY_NR : string;
procedure SetOPPORTUNITY_NR(const aOPPORTUNITY_NR: string);
function GetOPPORTUNITY_NR: string;
public
property OPPORTUNITY_NR: string read GetOPPORTUNITY_NR write SetOPPORTUNITY_NR;
implementation
procedure TTypeName.SetOPPORTUNITY_NR(const aOPPORTUNITY_NR: string);
begin
if (SpecialStrUtils_13.IsBlankStr(aOPPORTUNITY_NR)) then
raise Exception.CreateFmt('OPPORTUNITY_NR cannot be empty');
FOPPORTUNITY_NR := aOPPORTUNITY_NR;
end;
function TTypeName.GetOPPORTUNITY_NR: string;
begin
if (SpecialStrUtils_13.IsBlankStr(FOPPORTUNITY_NR)) then
raise Exception.CreateFmt('OPPORTUNITY NUMBER not set');
Result := FOPPORTUNITY_NR;
end;
Run Code Online (Sandbox Code Playgroud)
在 C# 中,我可以像这样编写上面的代码:
private string? _opportunityNr = null;
public string OpportunityNr
{
get => _opportunityNr ?? throw new Exception("Opportunitynr not set"); …Run Code Online (Sandbox Code Playgroud) sql ×6
sql-server ×6
t-sql ×6
c# ×5
.net ×1
async-await ×1
cross-apply ×1
decompiling ×1
delphi ×1
interface ×1
properties ×1
sql-like ×1
sta ×1
wpf ×1