小编snr*_*snr的帖子

是什么 ?[]?C#中的语法?

虽然我正在研究委托实际上是一个抽象类中Delegate.cs,我看到了下面的方法中,我不明白

  • 为什么返回值使用?它已经是一个引用()类型
  • ?[]? 参数的含义

你能解释一下吗?

public static Delegate? Combine(params Delegate?[]? delegates)
{
    if (delegates == null || delegates.Length == 0)
        return null;

    Delegate? d = delegates[0];
    for (int i = 1; i < delegates.Length; i++)
        d = Combine(d, delegates[i]);

    return d;
}
Run Code Online (Sandbox Code Playgroud)

.net c# null-coalescing-operator null-coalescing nullable-reference-types

88
推荐指数
3
解决办法
6255
查看次数

为什么 Count() 方法使用“checked”关键字?

当我在寻找Count 和 Count() 之间的区别时,我想看一眼Count(). 我看到以下代码片段,我想知道为什么checked需要/需要关键字:

int num = 0;
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
    while (enumerator.MoveNext())
    {
        num = checked(num + 1);
    }
    return num;
}
Run Code Online (Sandbox Code Playgroud)

源代码:

// System.Linq.Enumerable
using System.Collections;
using System.Collections.Generic;

public static int Count<TSource>(this IEnumerable<TSource> source)
{
    if (source == null)
    {
        ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
    }
    ICollection<TSource> collection = source as ICollection<TSource>;
    if (collection != null)
    {
        return collection.Count;
    }
    IIListProvider<TSource> iIListProvider = source as IIListProvider<TSource>;
    if (iIListProvider != null)
    {
        return …
Run Code Online (Sandbox Code Playgroud)

c# checked

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

确定lambda表达式在Java中是无状态还是有状态

是否有一个函数接受对lambda表达式的引用并返回一个布尔值,表示lambda表达式是否为无状态?如何确定lambda表达式的有状态?

java lambda java-8 java-9

20
推荐指数
2
解决办法
1604
查看次数

指定before/after :: operator的通用方法引用类型

以下方法引用之间有什么区别,

BiPredicate<List<String>,String> contains1 = List<String>::contains;

BiPredicate<List<String>,String> contains2 = List::<String>contains;

BiPredicate<List<String>,String> contains3 = List<String>::<String>contains;
Run Code Online (Sandbox Code Playgroud)

案件有特殊名称吗?有没有类似用法的例子?

java generics java-8 method-reference

17
推荐指数
2
解决办法
656
查看次数

/*ARGSUSED*/和其他特别评论

我搜索了SO并用Google搜索,但我没有得到它们的含义.他们和他们的目的是什么?他们什么时候用?我想也许在现代编程和我这一代中,我已经来不及看到它们了.

其中一些是AFAIS,

/*ARGSUSED的示例代码*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#define BUFSIZE 1024
#define TEN_MILLION 10000000L


/* ARGSUSED */
void *threadout(void *args) {
    char buffer[BUFSIZE];
    char *c;
    struct timespec sleeptime;

    sleeptime.tv_sec = 0;
    sleeptime.tv_nsec = TEN_MILLION;
    snprintf(buffer, BUFSIZE, "This is a thread from process %ld\n",
             (long)getpid());
    c = buffer;
    /*****************start of critical section ********************/
    while (*c != '\0') {
        fputc(*c, stderr);
        c++;
        nanosleep(&sleeptime, NULL);
    }
    /*******************end of critical section ********************/ …
Run Code Online (Sandbox Code Playgroud)

c comments

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

美化(格式化)Visual Studio代码中的Java代码

我已经在这里这里尝试了一些建议,但没有一个有效.你是如何为Java代码完成的,还是有通用的方法?En passant,我已经安装了XML格式化程序,以便它可以工作,但不是.

在此输入图像描述 在此输入图像描述

code-formatting visual-studio-code

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

格式字符串中的条件字符串 (f"{...}")

如您所知,Python 3.6 有一个称为格式字符串文字的功能。str(obj['my_str_index'])可以是None或者一个字符串值。'null'我已经尝试过下面的一种,但如果是的话,它不会产生文本None

foo = "soner test " \
f"{str(obj['my_str_index']) if str(obj['my_str_index']) is not None else 'null'}
Run Code Online (Sandbox Code Playgroud)

python string format python-3.x

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

无法将“System.Int32”类型的对象转换为“System.Int64”类型

如果错误无法将 object of type 转换System.Int64为 typeSystem.Int32,我会理解这是由于数据缩小的可能性。但是,我不明白为什么会出现错误,无法将 type 的 object 强制转换System.Int32为 typeSystem.Int64,尽管范围long更高。

int[]             integers = { 1, 2, 3 };
IEnumerable<long> test1    = integers.OfType<long>(); 
IEnumerable<long> test2    = integers.Cast<long>();

foreach (var l in test2) ;
Run Code Online (Sandbox Code Playgroud)

c# casting type-conversion

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

Java中方法重载异常

您能详细解释一下为什么预期结果不正确吗?正如大多数读者期望的输出是Byte Char Int Byte,但这当然不是正确的答案。

public class Tester {
    
    public static String test(byte b) {
        return "Byte ";
    }
    
    public static String test(char c) {
        return "Char ";
    }
    
    public static String test(int i) {
        return "Int ";
    }
    
    public static void main(String[] args) {
        byte b = 0;
        char c = 'A';
        System.out.print(test(true  ? b : c));
        System.out.print(test(false ? b : c));
        System.out.print(test(true  ? 0 : 'A'));
        System.out.print(test(false ? 'A' : (byte)0));
    }
}
Run Code Online (Sandbox Code Playgroud)

正确的结果是Int Int Char …

java overloading

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

正在运行时中断汇编指令

当中断到达 CPU 时,如果它被确认,则通过在跳转到处理程序之前保存当前地址位置来处理它。否则将被忽略。

我想知道汇编指令调用是否被中断。

例如,

mvi a, 03h ; put 3 value into acc. in 8080 assembly
Run Code Online (Sandbox Code Playgroud)

一行指令可以中断吗?或者如果不是,它是原子的?

是否总能保证“一行汇编指令”总是原子的?

如果8080汇编中没有“lock”关键字呢,那么原子性是如何提供的呢?

例如,如果要操作64位和,但是“一行​​指令”没有办法做到,并且在对和进行操作时出现中断怎么办?如何在装配级别防止它?

对我来说,这个概念正在开始归结。

assembly interrupt cpu-architecture atomicity interrupted-exception

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