小编Bro*_*dow的帖子

Array.Length和Array.Count()之间的差异

可能重复:
集合Array.Length与Array.Count中的计数与长度与大小的
关系

我声明了这个数组:

int[] misInts = new Int[someNumber];

/* make some happy operations with the elements in misInts */
Run Code Online (Sandbox Code Playgroud)

所以我可以得到SomeNumber的值:misInts.Length或misInts.Count()

C#中的数组继承自IEnumerable.所以,如果我有:

Func<int> misIntsF = Enumerable.Range(0, someNumber).Select(c=> /* make some happy operations that return Integers */);
Run Code Online (Sandbox Code Playgroud)

我被告知,如果我创建misIntsF.Count(),我实际上执行Lambda表达式中的代码,获取结果并计算它们.但阵列misInts没有Lambda表达.

是misInts.Count()比misInts更多的内存消耗.Length?misInts.Count()和misInts.Length之间有什么区别?

c# arrays

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

你觉得VS和Intellisense让我们变得笨拙吗?

我读了这篇文章,"Intellisense"和"Generated Code"的部分内容:

http://www.charlespetzold.com/etc/DoesVisualStudioRotTheMind.html

你认为作者是对的吗?

我不同意Intellisense对程序员来说太糟糕了.VS for C#用于"隐藏"另一个文件中的控件事件,但如果您对该语言有足够的了解,可以找到它们,并且可以手动修改它们.使用VS,我不需要记住我使用的所有.Net类.我认为如果您使用IDE或记事本并不重要,但是,如果这些RAD工具存在并且是免费的......为什么不使用它们呢?

ide visual-studio

9
推荐指数
4
解决办法
2010
查看次数

VB6中"Null"和"Nothing"有什么区别?

我有一个这样的记录集:

Dim rs as Recordset
Set rs as New Recordset

'... a lot of coding ...

if Err.Number <> 0 Then ' oops, something gone wrong!
    If rs.State <> adStateClosed Then rs.Close
    Set rs = Nothing
end if

' I want to evaluate if rs is Nothing, or Null

if rs is Nothing then 
' this doesn't throw errors, and works well :D
end if

if rs is Null then
' this throws an error of "types not compatible"
end …
Run Code Online (Sandbox Code Playgroud)

vb6

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

Mac book Pro 上的 Docker Desktop 安装错误 - OS Monterey - 错误:调用远程方法“desktop-go-backend”时出错

我尝试使用 Docker Desktop for Mac(英特尔芯片)安装 Docker Desktop,但失败并出现以下错误:

\n
Error invoking remote method \'desktop-go-backend\': Error: {"message":"installing vmnetd: retrieving vmnetd version from /Library/LaunchDaemons/com.docker.vmnetd.plist: reading plist /Library/LaunchDaemons/com.docker.vmnetd.plist: open /Library/LaunchDaemons/com.docker.vmnetd.plist: no such file or directory\\\\ngithub.com/docker/pinata/mac/tools/install/privileged.getValueFromPlist\\\\n\\\\tgithub.com/docker/pinata/mac/tools/install/privileged/vmnetd.go:175\\\\ngithub.com/docker/pinata/mac/tools/install/privileged.setupVmnetd\\\\n\\\\tgithub.com/docker/pinata/mac/tools/install/privileged/vmnetd.go:85\\\\ngithub.com/docker/pinata/mac/tools/install/privileged.ApplyCustomConfiguration\\\\n\\\\tgithub.com/docker/pinata/mac/tools/install/privileged/privileged.go:137\\\\ngithub.com/docker/pinata/mac/tools/install/privileged.ConfigCmd.func1\\\\n\\\\tgithub.com/docker/pinata/mac/tools/install/privileged/privileged.go:59\\\\ngithub.com/spf13/cobra.(\\*Command).execute\\\\n\\\\tgithub.com/spf13/cobra@v1.7.0/command.go:940\\\\ngithub.com/spf13/cobra.(\\*Command).ExecuteC\\\\n\\\\tgithub.com/spf13/cobra@v1.7.0/command.go:1068\\\\ngithub.com/spf13/cobra.(\\*Command).Execute\\\\n\\\\tgithub.com/spf13/cobra@v1.7.0/command.go:992\\\\nmain.main\\\\n\\\\tgithub.com/docker/pinata/mac/tools/install/main.go:185\\\\nruntime.main\\\\n\\\\truntime/proc.go:250\\\\nruntime.goexit\\\\n\\\\truntime/asm_amd64.s:1598\\\\ngithub.com/docker/pinata/mac/tools/install/privileged.setupVmnetd\\\\n\\\\tgithub.com/docker/pinata/mac/tools/install/privileged/vmnetd.go:87\\\\ngithub.com/docker/pinata/mac/tools/install/privileged.ApplyCustomConfiguration\\\\n\\\\tgithub.com/docker/pinata/mac/tools/install/privileged/privileged.go:137\\\\ngithub.com/docker/pinata/mac/tools/install/privileged.ConfigCmd.func1\\\\n\\\\tgithub.com/docker/pinata/mac/tools/install/privileged/privileged.go:59\\\\ngithub.com/spf13/cobra.(\\*Command).execute\\\\n\\\\tgithub.com/spf13/cobra@v1.7.0/command.go:940\\\\ngithub.com/spf13/cobra.(\\*Command).ExecuteC\\\\n\\\\tgithub.com/spf13/cobra@v1.7.0/command.go:1068\\\\ngithub.com/spf13/cobra.(\\*Command).Execute\\\\n\\\\tgithub.com/spf13/cobra@v1.7.0/command.go:992\\\\nmain.main\\\\n\\\\tgithub.com/docker/pinata/mac/tools/install/main.go:185\\\\nruntime.main\\\\n\\\\truntime/proc.go:250\\\\nruntime.goexit\\\\n\\\\truntime/asm_amd64.s:1598"}\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试卸载并重新安装适用于 mac 的 Docker 桌面几次。它没有解决问题。然后我找到了这个答案 - Unable to finish Docker Install on Mac book Error invoking Remote method 'desktop-go-backend'

\n

我尝试了命令 -brew install --cask docker

\n

它说以下错误:\'/Applications/Docker.app\' 已经有一个应用程序。

\n

我尝试运行命令 -

\n
/Applications/Docker.app/Contents/MacOS/uninstall\n
Run Code Online (Sandbox Code Playgroud)\n

并得到 zsh: 没有这样的文件或目录:/Applications/Docker.app/Contents/MacOS/uninstall

\n

我运行命令来检查 Docker 安装在哪里

\n
ls -ltrh /usr/local/bin/docker\nlrwxr-xr-x  1 root …
Run Code Online (Sandbox Code Playgroud)

docker docker-compose docker-daemon

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

与垃圾收集语言一起使用时,哪种代码的CPU /内存效率更高?

我有两个虚拟代码片段(让我们考虑它们是用Java或C#编写的,所有变量都是本地的):

代码1:

int a;
int b = 0;

for (int i = 1; i < 10 ; i++)
{
    a = 10;
    b += i;

    // a lot of more code that doesn't involve assigning new values to "a"
}
Run Code Online (Sandbox Code Playgroud)

代码2:

int b = 0;

for (int i = 1; i < 10 ; i++)
{
    int a = 10;
    b += i;

    // a lot of more code that doesn't involve assigning new values to "a"
}
Run Code Online (Sandbox Code Playgroud)

乍一看,我会说两个代码都消耗相同的内存量,但代码1的CPU效率更高,因为它只创建和分配变量a …

c# java garbage-collection

7
推荐指数
2
解决办法
1843
查看次数

C#中的15位数的Double Type精度是不是?

我正在测试Brainteasers的代码:

        double d1 = 1.000001;

        double d2 = 0.000001;

        Console.WriteLine((d1 - d2) == 1.0);
Run Code Online (Sandbox Code Playgroud)

结果是"假的".当我更改数据类型时:

        decimal d1 = 1.000001M;

        decimal d2 = 0.000001M;

        decimal d3 = d1-d2;

        Console.WriteLine(d3 == 1);
Run Code Online (Sandbox Code Playgroud)

该程序写出正确的答案:"真".

此问题仅在浮点后使用6位数.15位数的精度怎么样?

c# precision types

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

我必须传递来自 CMSSignedData 对象的哪些数据才能生成有效的时间戳?

我有一个有效的 PKCS7 文件加载到 CMSSignedData 对象中。此 PKCS7 文件包括纯文本消息和有效的附加数字签名(都在同一个文件中)。

现在我想给这个文件加上时间戳。这是我正在使用的代码(源代码):

 private static CMSSignedData addTimestamp(CMSSignedData signedData)
throws Exception {
        Collection ss = signedData.getSignerInfos().getSigners();
        SignerInformation si = (SignerInformation) ss.iterator().next();

        TimeStampToken tok = getTimeStampToken();

        ASN1InputStream asn1InputStream = new ASN1InputStream
(tok.getEncoded());
        DERObject tstDER = asn1InputStream.readObject();
        DERSet ds = new DERSet(tstDER);

        Attribute a = new Attribute(new
DERObjectIdentifier("1.2.840.113549.1.9.16.2.14"), ds);
        DEREncodableVector dv = new DEREncodableVector();
        dv.add(a);
        AttributeTable at = new AttributeTable(dv);
        si = SignerInformation.replaceUnsignedAttributes(si, at);
        ss.clear();
        ss.add(si);
        SignerInformationStore sis = new SignerInformationStore(ss);

        signedData = CMSSignedData.replaceSigners(signedData, sis);
        return …
Run Code Online (Sandbox Code Playgroud)

java validation bouncycastle trusted-timestamp pkcs#7

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

服务器没有返回数据时ag-grid继续显示加载图标

我在 Ag-grid (Angular) 中遇到了奇怪的行为。当我使用 serverSide 选项并且服务器没有返回数据时,网格将显示 cacheBlockSize 中提到的所有行的加载图标。我尝试了尽可能多的选项来隐藏这些空的加载行,但没有任何结果。

我尝试在官方示例页面中复制相同的内容。幸运的是,我可以复制类似的行为。请参阅官方示例页面的编辑版本,其中我从假服务器调用中传递了一个空数组:

https://plnkr.co/edit/Egw9ToJmNE7Hl6Z6

  onGridReady(params) {
    this.gridApi = params.api;
    this.gridColumnApi = params.columnApi;

    this.http
      .get('https://www.ag-grid.com/example-assets/olympic-winners.json')
      .subscribe((data) => {
        let idSequence = 0;
        data.forEach((item) => {
          item.id = idSequence++;
        });
        const server = new FakeServer(data);
        const datasource = new ServerSideDatasource(server);
        params.api.setServerSideDatasource(datasource);
      });
  }
}

function ServerSideDatasource(server) {
  return {
    getRows: (params) => {
      setTimeout(() => {
        const response = server.getResponse(params.request);
        if (response.success) {
          params.successCallback(response.rows, response.lastRow);
        } else {
          params.failCallback();
        }
      }, 2000);
    },
  };
}
function …
Run Code Online (Sandbox Code Playgroud)

ag-grid ag-grid-angular

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

识别相同OleDbException类型的异常

我有以下代码来验证另一个应用程序(数据库已经有密码)是否在独占模式下打开MSAccess 2003数据库:

OleDbConnectionStringBuilder conString = new OleDbConnectionStringBuilder();
conString.Provider = "Microsoft.Jet.OLEDB.4.0";
conString.DataSource = "some path to some mdb file";
// I don't care about the password, 
// I just whant to know if it is opened in Exclusive Mode
conString["Jet OLEDB:Database Password"] = String.Empty;
conString["Mode"] = "Share Deny None";
string completeConnStr = conString.ConnectionString;

using (OleDbConnection con = new OleDbConnection(completeConnStr))
{
      try
      {
         con.Open();
         con.Close();
      }
      catch (Exception ex)
      {
         string s = ex.Message;
      }
}
Run Code Online (Sandbox Code Playgroud)

当在独占模式下打开数据库时,它不关心密码,它会抛出OleDbException并显示以下消息:"文件已在使用中".当数据库不处于独占模式并收到错误的密码时,它会抛出一个OleDbException并显示一条消息:"它不是有效的密码".

我如何识别这两个例外?密码验证是在另一种方法中进行的,所以我只想知道数据库是否以独占模式打开,然后用"请输入密码"对话框来烦扰用户.

c# exception

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

为什么这段代码不能编译? - 对象赋值,调用,递增,递减和new可用作指令

我正在使用Visual Studio Express 2008在C#中测试一些代码:

delegate void Hm(int k);

static void Main(string[] args)
{
    char[] m = new char[10];

    m[0] = 'H'; m[5] = 'M';
    m[1] = 'o'; m[6] = 'u';
    m[2] = 'l'; m[7] = 'n';
    m[3] = 'a'; m[8] = 'd';
    m[4] = ' '; m[9] = 'o';

    unsafe { fixed (char* p = m) { Hm H = (k) => recurd(k, p); H(0); } }
    Console.ReadLine();
}

static unsafe int recurd(int i, char* p) 
{
      Console.WriteLine(p[i]); 
      if (i …
Run Code Online (Sandbox Code Playgroud)

c#

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

在 Python 2.7 中编码时如何处理 Linux 上带有空格的路径?

我有一个 python 脚本来处理 Linux Mint 目录中的文件。部分代码如下所示:

path_to_dir = "/home/user/Im a folder with libs to install/"

if os.path.isdir(path_to_dir):
    print "it can locate the directory"
    os.chdir(path_to_dir) # everything ok here :D
    subprocess.call(['./configure'], shell = True)
    subprocess.call(['make'], shell = True)
    subprocess.call(['make install'], shell = True) # problem happens here
Run Code Online (Sandbox Code Playgroud)

执行subprocess.call(['make install'], shell = True)时抛出这个错误:

/bin/bash: /home/user/Im: No such file or directory
make[3]: *** [install-libLTLIBRARIES] Error 127
make[2]: *** [install-am] Error 2
make[1]: *** [install-recursive] Error 1
make: *** [install-recursive] Error 1 …
Run Code Online (Sandbox Code Playgroud)

linux python-2.7

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

是否有必要释放.Net中的内存,就像在VB6中一样?

我正在阅读VB6中Form的事件,如"Unload","QueryUnload"和"Terminate",以及"End"语句:https ://web.archive.org/web/1/http //articles . techrepublic%2ecom%2ecom/5100-10878_11-5533338.html http://visualbasic.freetutes.com/learn-vb6-advanced/lesson6/p5.html

我曾经遇到过VB6应用程序的问题(它调用了很多windows的api).当我在主窗体的Unload事件中"结束"时,它崩溃了整个IDE!当我小心地关闭所有连接时,停止我的计时器,将所有形式设置为零,并且在完成所有清洁过程之后,将"结束"放在主表单的终止事件的最后一行,一切都正常.没有更多崩溃:)

我的问题是,是否有必要在.Net环境中完成所有这些"清理过程".我知道垃圾收集器会清除所有可能导致问题的剩余位.

或者,无论是VB6还是.Net,在"结束"您的应用程序之前清理所有内容都是一种很好的做法?

.net vb6 garbage-collection

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

如何使用名称包含空格的表中的"选择"语句?

使用此SQL查询时:"Select*from table_name"

如果表的名称包含空格,会发生什么?是否有一个特殊的SQL sintax用于选择名称如"作者代码"的表?

sql select

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