小编Dai*_*Dai的帖子

为什么不能推断嵌套泛型类型?

鉴于以下课程......

public abstract class FooBase<TBar> where TBar : BarBase{}
public abstract class BarBase{}
public class Bar1 : BarBase{}
public class Foo1 : FooBase<Bar1> {}
Run Code Online (Sandbox Code Playgroud)

......以及以下方法......

public TBar DoSomething<TFoo, TBar>(TFoo theFoo)
    where TFoo : FooBase<TBar>
    where TBar : BarBase
{
    return default(TBar);
}
Run Code Online (Sandbox Code Playgroud)

为什么以下代码行不能表示返回类型?

Bar1 myBar = DoSomething(new Foo1());
Run Code Online (Sandbox Code Playgroud)

相反,我必须指定像这样的泛型类型......

Bar1 myBar = DoSomething<Foo1, Bar1>(new Foo1());
Run Code Online (Sandbox Code Playgroud)

.net c# generics nested-generics

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

如何更改 Flexbox 中仅一个元素的间隙?

我正在使用 css flexbox 创建一些东西,并使用间隙来给出元素之间的间距,但现在我只想更改一个元素的间距,例如

.container{
  display: flex;
  gap: 20px;
}

.items{
  width: 100px; 
  height: 100px;
  background: red;
  
}

.item-4{
  background: blue;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
  <div class="items item-1"></div>
  <div class="items item-2"></div>
  <div class="items item-3"></div>
  <div class="items item-4"></div>
  <div class="items item-5"></div>
  <div class="items item-6"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

现在我想将蓝色框的间隙从 20px 更改为 5px 有什么方法可以做到这一点

html css flexbox

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

将递归转换为'尾递归'

我有一个关于如何将'recursion'转换为'tail recursion'的问题.这不是一个功课,只是当我试图从算法书中修改递归定理时弹出一个问题.我熟悉使用递归(factorial和Fibonacci序列)的两个典型示例,并且还知道如何以递归方式和尾递归方式实现它们.我的代码如下(我使用Perl只是为了简单,但可以很容易地转换为C/Java/C++)

#this is the recursive function
sub recP    {
    my ($n) = @_;
    if ($n==0 or $n==1 or $n==2)    {
        return 1;
    } else {
        return (recP($n-3)*recP($n-1))+1;
    }

}
for (my $k=1;$k<10;$k++) {
    print "*"x10,"\n";
    print "recP($k)=", recP($k), "\n";
}
Run Code Online (Sandbox Code Playgroud)

运行代码时,输​​出如下:

recP(1)=1 
recP(2)=1 
recP(3)=2 
recP(4)=3 
recP(5)=4 
recP(6)=9 
recP(7)=28 
recP(8)=113 
recP(9)=1018 
Run Code Online (Sandbox Code Playgroud)

在返回之前,递归函数用不同的参数调用自己两次; 我尝试了几种方法将其转换为尾递归方式,但都错了.

任何人都可以查看代码并向我展示使其尾递归的正确方法吗?特别是我相信这个树递归的转换有一个例程(在返回之前多次调用递归函数),可以对此有所了解吗?所以我可以使用相同的逻辑来处理不同的问题.提前致谢.

algorithm recursion

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

C#中的`params`会不会导致每次调用都分配一个新的数组?

C#/ .NET通过传递Array类型by-reference来具有可变参数函数参数(与C/C++相反,它只是将所有值直接放在堆栈上,无论好坏).

在C#世界中,这有一个很好的优点,允许您使用'raw'参数或可重用的数组实例调用相同的函数:

CultureInfo c = CultureInfo.InvariantCulture;

String formatted0 = String.Format( c, "{0} {1} {2}", 1, 2, 3 );

Int32 third = 3;
String formatted0 = String.Format( c, "{0} {1} {2}", 1, 2, third );

Object[] values = new Object[] { 1, 2, 3 };
String formatted1 = String.Format( c, "{0} {1} {2}", values );
Run Code Online (Sandbox Code Playgroud)

这意味着生成的CIL相当于:

String formatted0 = String.Format( c, "{0} {1} {2}", new Object[] { 1, 2, 3 } );

Int32 third = 3;
String formatted0 …
Run Code Online (Sandbox Code Playgroud)

.net c# variadic-functions

14
推荐指数
3
解决办法
2507
查看次数

与实体不对应的RESTful操作/服务?

我喜欢RESTful的简单性以及它如何避免像SOAP这样的普通"企业"系统,或DCOM和RPC的二进制硬度.

但REST似乎比更抽象的服务更适合数据库实体.我想知道你是否可以告诉我你如何做这些情况:

例如,假设我有一个用于普通数据库系统的RESTful Web服务(例如,乳品购物网站),所以我有/ products/eggs/battery和/ products/milk/skimmed

通过对/ products/eggs进行POST来实现INSERT.

但你怎么做一个"清除所有"命令?DELETE动词仅适用于单个实体.而"DELETE/products/milk"意味着删除"牛奶"产品类别本身,而不仅仅是牛奶类别中的所有产品.如果你想完成两件事怎么办?

我遇到的另一个问题涉及与实体无关的Web服务操作.例如,如果我正在为密码数据库设计一个Web服务,我会有"GET /passwords/stackoverflow.com"之类的操作,这很好,但我也有操作在入侵的情况下禁用该网站检测.在"旧学校"网络服务模式下,我有一个名为"disableWebsite"的方法,但是我不能创建一个名为"DISABLE"的HTTP动词和一个名为"/ website"的资源(所以请求将是" DISABLE /网站").这里有什么解决方案?

最后,如何将HTML表单与RESTful协调?Web表单只能使用查询字符串或POST进行GET请求.如果我有搜索表单,我希望它请求"/ products/search/{query}",但现在请求看起来像"/ products/search?query = {query}".

rest

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

在 flutter 中将 Stream&lt;List&lt;String&gt;&gt; 转换为 List&lt;String&gt;

我正在尝试将 a 转换Stream<List<String>> to List<String>为 flutter 这是我的代码

Stream<List<String>> _currentEntries;

/// A stream of entries that should be displayed on the home screen.
Stream<List<String>> get categoryEntries => _currentEntries;
Run Code Online (Sandbox Code Playgroud)

_currentEntries正在使用数据库中的数据进行填充。我想转换_currentEntriesList<String>

我尝试了以下代码但不起作用:

List<List<String>> categoryList () async  {
  return await _currentEntries.toList();
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

List<List<String>>无法从方法返回type 的值,categoryList因为它的返回类型为List<List<String>>

有人可以帮助如何解决这个问题并将 a 转换Stream<List<String>为 吗List<String>

dart flutter

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

如何使用lambda表达式连接3个表?

我有一个简单的LINQ lambda连接查询,但我想添加一个带有where子句的第3个连接.我该怎么做呢?

这是我的单个连接查询:

var myList = Companies
    .Join(
        Sectors,
        comp => comp.Sector_code,
        sect => sect.Sector_code,
        (comp, sect) => new {Company = comp, Sector = sect} )
    .Select( c => new {
        c.Company.Equity_cusip,
        c.Company.Company_name,
        c.Company.Primary_exchange,
        c.Company.Sector_code,
        c.Sector.Description
    });
Run Code Online (Sandbox Code Playgroud)

我想将以下SQL命令添加到上面的LINQ查询中并仍然保持投影:

SELECT
    sector_code, industry_code 
FROM
    distribution_sector_industry 
WHERE
    service = 'numerical'
Run Code Online (Sandbox Code Playgroud)

第3次连接将使用Sector_code上的Sector表和Distribution_sector_industry进行.

提前致谢.

c# linq lambda join

12
推荐指数
3
解决办法
5万
查看次数

Windows 10 Game-Bar是如何实现的?

在Windows 10中按Windows Key+ G会导致Xbox游戏栏打开 - 它覆盖当前应用程序,无论它是否是游戏(尽管Windows维护自己的游戏数据库作为在进程启动时自动显示栏的提示)

我想知道这是怎么可能的 - 我没有在我的计算机上运行任何与Windows 10 Xbox App相关的进程.

Process Explorer显示按下WinKey + G时,会发生以下情况:

  1. 一个svchost.exe实例(托管BrokerInfrastructure,DcomLaunch,LSM,PlugPlay Power,和SystemEventsBroker服务)调用"%windir%\System32\bcastdvr.exe" -ServerName:Windows.Media.Capture.Internal.BroadcastDVRServer
  2. bcastdvr.exe然后调用"C:\Windows\System32\GamePanel.exe {hexString} /eventType=8(其中{hexString}是一个16位十六进制数字(8字节)字符串,可能是一个窗口句柄或等效字符串).
  3. GamePanel.exe 然后创建窗口.

但是叠加窗口本身是特殊的 - 它似乎不正常hWnd- 例如,我观察到我的鼠标光标失去了它的阴影和"声纳脉冲"效果(当我点击Ctrl键来显示我的光标位置时)当我打开游戏栏时,我的鼠标光标停留在原位.我还注意到游戏栏的动画是多么流畅和流畅 - 与典型的Win32窗口完全不同.它是否使用XAML UI框架?如果是这样,它是如何在Windows UWP Sandbox之外进行的?

奇怪的是,游戏栏也能够瞄准高架窗户.

我尝试 - 并且失败 - 使用Spy ++检查窗口,因为它会在另一个窗口获得焦点后立即消失 - 但是当我选择开始录制窗口时(因此您获得了始终保留在屏幕上的录制叠加层),叠加层我一使用Spy ++的"查找窗口"工具就消失了.GameBar Recording Overlay如何做到这一点?

windows-10

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

使用select语句合并插入

这适合我

MERGE Table1 AS tgt
USING
(
    SELECT
        TOP 1
        *
    FROM
        Table2,
        (
            SELECT
                itmid
            FROM
                Table3
            WHERE
                id = @id
        ) as a
    WHERE
        id = @id
) AS src
ON ( tgt.id = src.id )
WHEN MATCHED THEN
    UPDATE SET qty = qty + @qty
WHEN NOT MATCHED THEN
    INSERT itmid
    VALUES itmid;
Run Code Online (Sandbox Code Playgroud)

但是,当我这样改变时,它不起作用,最后显示错误 select

MERGE Table1 AS tgt
USING
(
    SELECT
        TOP 1
        *
    FROM
        Table2
    WHERE
        id = @id
) AS src
ON ( tgt.id …
Run Code Online (Sandbox Code Playgroud)

sql sql-server merge sql-server-2008-r2

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

mscorlib 的“System.Boolean”如何避免结构布局循环?

System.Boolean参考源网站上的源代码声明 的实例struct Boolean仅包含一个bool字段private bool m_value::

https://referencesource.microsoft.com/#mscorlib/system/boolean.cs,f1b135ff6c380b37

namespace System {

    using System;
    using System.Globalization;
    using System.Diagnostics.Contracts;

    [Serializable]
    [System.Runtime.InteropServices.ComVisible(true)]
    public struct Boolean : IComparable, IConvertible
#if GENERICS_WORK
        , IComparable<Boolean>,  IEquatable<Boolean>
#endif
    {
      private bool m_value;

      internal const int True = 1; 
      internal const int False = 0; 

      internal const String TrueLiteral  = "True";
      internal const String FalseLiteral = "False";

      public static readonly String TrueString  = TrueLiteral;
      public static readonly String FalseString = FalseLiteral;
}
Run Code Online (Sandbox Code Playgroud)

但我注意到... …

c#

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