考虑带有委托的逆变接口定义:
public interface IInterface<in TInput>
{
delegate int Foo(int x);
void Bar(TInput input);
void Baz(TInput input, Foo foo);
}
Run Code Online (Sandbox Code Playgroud)
Baz失败的定义出现错误:
CS1961
无效方差:类型参数“TInput”必须在“IInterface<TInput>.Baz(TInput, IInterface<TInput>.Foo)”上协变有效。'TInput' 是逆变的。
我的问题是为什么?乍一看,这应该是有效的,因为Foo委托与TInput. 我不知道是编译器过于保守还是我遗漏了什么。
请注意,通常您不会在接口内声明委托,特别是这不会在早于 C# 8 的版本上编译,因为接口中的委托需要默认接口实现。
如果允许这个定义,有没有办法打破类型系统,或者编译器是否保守?
c# generics covariance contravariance default-interface-member
在微软文档中,复杂度表示为O(n)
但如果你看看实施情况
foreach (T item in other)
{
if (Contains(item))
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
,然后对每个元素调用搜索方法,其复杂度为 O(m*log(n))
谁是真正正确的?
SQLLocalDB 无法启动并抛出如下错误。
**C:\Windows\system32>sqllocaldb c MSSQLLocalDB**
Creation of LocalDB instance "MSSQLLocalDB" failed because of the following error:
Error occurred during LocalDB instance startup: SQL Server process failed to start.
***Note:*** Command started with Run as Administrator.
Run Code Online (Sandbox Code Playgroud)
事件查看器显示以下日志:
Windows API call WaitForMultipleObjects returned error code: 575. Windows system error message is: {Application Error}
The application was unable to start correctly (0x%lx). Click OK to close the application.
Reported at line: 3714.
Source: SQLLocalDB 15.0
Event ID: 528
Level: Error
Run Code Online (Sandbox Code Playgroud)
操作系统: Windows 11 …
考虑以下代码:
private unsafe void Function()
{
int length;
// This line raises error CS1686, "Local 'length' or its members cannot have their address taken and be used inside an anonymous method or lambda expression".
glGetProgramiv(1, GL_PROGRAM_BINARY_LENGTH, &length);
FunctionWithLambda(() => Console.WriteLine(length));
}
private void FunctionWithLambda(Action callback)
{
callback();
}
Run Code Online (Sandbox Code Playgroud)
length请注意,我获取(局部变量)的地址,然后在 lambda 中使用该变量本身(而不是其地址)。我理解为什么局部变量地址不能直接在 lambda 中使用(参见为什么不能将变量的地址传递给匿名函数?等示例),但是为什么我不能使用一次分配的值length(即使该赋值碰巧使用了&运算符)?错误 CS1686 的官方文档(https://learn.microsoft.com/bs-latn-ba/dotnet/csharp/misc/cs1686)尚未澄清这种混乱。
我的假设是,这只是一种语言限制,但我很好奇是否有我遗漏的潜在技术原因。另请注意,我不是问如何解决这个问题(我知道我可以length先轻松复制到另一个局部变量)。
我有一个带有自动递增id和跨两列的唯一约束的表,keycol1并且keycol2.
假设表中有这样的数据:
H| (id, keycol1, keycol2, col1, col2)
| (1, 'A', 'B', 'A', 'E' )
| (2, 'A', 'C', 'J', 'K' )
| (3, 'A', 'D', 'H', 'I' )
Run Code Online (Sandbox Code Playgroud)
然后我使用一条MERGE语句来更新对应于的所有记录keycol1:
MERGE tablename trg
USING (VALUES ('A','B','C','D'),
('A','C','E','F'),
('A','E','K','F'),
('A','F','L','M')) src(keycol1, keycol2, col1, col2)
ON trg.keycol = src.keycol AND trg.keycol2 = src.keycol2
WHEN MATCHED THEN
UPDATE
SET col1 = src.col1, col2 = src.col2
WHEN NOT MATCHED THEN
INSERT (keycol1, keycol2, col1, …Run Code Online (Sandbox Code Playgroud) 我可以列出重复的电子邮件。
但我无法列出整行,其中包含其他字段,例如EmployeeId、Username、FirstName、LastName等。
SELECT
Email,
COUNT(Email) AS NumOccurrences
FROM EmployeeProfile
GROUP BY Email
HAVING ( COUNT(Email) > 1 )
Run Code Online (Sandbox Code Playgroud)
Email我可以知道如何列出包含在表中多次出现的行中的所有字段吗?
我有一个带有日期 ( session_date) 和值 ( price) 的 SQL Server 表。
| 会话日期 | 价格 |
|---|---|
| 2022-12-31 | 10 |
| 2022-12-30 | 9 |
| 2022年12月29日 | 5 |
| 2022年12月28日 | 7 |
| 2022年12月27日 | 2 |
| 2022-12-26 | 9 |
| 2022年12月25日 | 3 |
| 2022年12月24日 | 1 |
我想计算最后 3 行(日期)的滚动最大值并检索与每个最大值关联的 session_date:
| 会话日期 | 价格 | 滚动最大 | 滚动最后日期 |
|---|---|---|---|
| 2022-12-31 | 4 | 9 | 2022年12月29日 |
| 2022-12-30 | 4 | 9 | 2022年12月29日 |
| 2022年12月29日 | 9 | 9 | 2022年12月29日 |
| 2022年12月28日 | 7 | 7 | 2022年12月28日 |
| 2022年12月27日 | 2 | 4 | 2022-12-26 |
| 2022-12-26 | 4 | 4 | 2022-12-26 |
| 2022年12月25日 | 3 | 3 | 2022年12月25日 |
| 2022年12月24日 | 1 | 1 | 2022年12月24日 |
我正在使用此查询来计算滚动最大值,但如何获取关联的session_date ?
select session_date
, price
, max(price) over …Run Code Online (Sandbox Code Playgroud) 例如
create table dbdt (
ID int,
Name varchar(255));
Run Code Online (Sandbox Code Playgroud)
当我查询时:
select * from dbName.information_schema.columns
where table_schema = 'schemaName' and table_name = 'dbdt'
Run Code Online (Sandbox Code Playgroud)
结果:
| COLUMN_NAME | 数据类型 |
|---|---|
| ID | 数字 |
| 姓名 | 文本 |
我需要在查询中更改什么才能返回INT并VARCHAR(255)在创建表时设置它?
对于兼容性级别问题,我无法使用 string_split 函数。我知道如何更改兼容性级别。但对于数据库的快速发展来说,如果旧功能失效就会存在一定的风险。
现在,兼容级别 110 中是否有 string_split 函数的替代方案?
或者如果我想定义它,函数会是什么?
这是OrderStatus枚举:
public enum OrderStatus\n {\n [Display(Name = "G\xc3\xb6zl\xc9\x99m\xc9\x99d\xc9\x99")]\n Pending,\n [Display(Name = "Q\xc9\x99bul olundu")]\n Accepted,\n [Display(Name = "L\xc9\x99\xc4\x9fv edildi")]\n Rejected,\n [Display(Name = "\xc3\x87atd\xc4\xb1r\xc4\xb1ld\xc4\xb1")]\n Delivered\n }\nRun Code Online (Sandbox Code Playgroud)\n这是Order模型:
public class Order : BaseEntity\n {\n public string AppUserId { get; set; }\n public AppUser AppUser { get; set; }\n [StringLength(255), Required]\n public string StoreName { get; set; }\n [StringLength(255), Required]\n public string StoreAddress { get; set; }\n public double TotalPrice { get; set; }\n public double RemainingBalance …Run Code Online (Sandbox Code Playgroud) c# ×5
sql-server ×5
sql ×4
t-sql ×4
.net ×1
.net-6.0 ×1
casting ×1
covariance ×1
enums ×1
generics ×1
integer ×1
lambda ×1
localdb ×1
over-clause ×1
snowflake-cloud-data-platform ×1
sortedset ×1
split ×1
sql-delete ×1
sql-merge ×1
types ×1