小编hon*_*pei的帖子

为什么Lookup在C#中是不可变的?

与之不同Dictionary,您无法Lookup通过逐个添加元素来构造.你碰巧知道原因吗?

Lookup就像multimap在C++中一样; 为什么我们不能在C#中修改它?如果我们真的不能,我们如何multimap在C#中构建数据结构?

c# lookup dictionary

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

std :: exception和"..."之间的区别

A:      catch(...)  
B:      catch(std::exception& e)
Run Code Online (Sandbox Code Playgroud)

问题是什么可以A捕获但B不能.

为什么在C++中没有引入可以捕获任何内容的通用根异常

---添加我很抱歉,我应该说我在C++中理解你可以抛出任何类型的int,但除此之外,还有什么可以抛出?

我的问题是我试图找到从代码抛出的异常,它可以被A但不是B捕获.这个异常绝对不是像"int"这样的类型.它必须是系统异常或内存违规.我只是想知道那可能是什么.

c++ exception

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

C++ 11 Exception的析构函数允许现在抛出?

任何想法为什么virtual~exception()throw()在C++ 98中,但virtual~exception()在C++ 11中?

什么是允许C++ 11投入类的析构函数的设计决策exception

这里:

C++ 98:

class exception {
public:
  exception () throw();
  exception (const exception&) throw();
  exception& operator= (const exception&) throw();
  virtual ~exception() throw();
  virtual const char* what() const throw();
}
Run Code Online (Sandbox Code Playgroud)

C++ 11:

class exception {
public:
  exception () noexcept;
  exception (const exception&) noexcept;
  exception& operator= (const exception&) noexcept;
  virtual ~exception();
  virtual const char* what() const noexcept;
}
Run Code Online (Sandbox Code Playgroud)

c++ destructor exception c++11 c++98

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

st_ :: aligned_storage的static_cast和reinterpret_cast

有人可以在http://en.cppreference.com/w/cpp/types/aligned_storage中解释关于铸造的一些代码吗?

可以使用以下代码

return *static_cast<const T*>(static_cast<const void*>(&data[pos]));
Run Code Online (Sandbox Code Playgroud)

被替换为

 return *reinterpret_cast<const T*>(&data[pos]);
Run Code Online (Sandbox Code Playgroud)

为什么这里使用两个铸件?非常感谢.

香港

c++ alignment static-cast reinterpret-cast

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

带有IN参数的SqlCommand问题

显然,以下代码不会按预期打印任何内容.我确信这与我尝试将项目列表放入的事实有关@namelist.显然,它不仅仅是文本替代品.

我怎么解决这个问题?谢谢

using (var connection = new SqlConnection(_connectionString))
{
    connection.Open();

    using (var cmd = connection.CreateCommand())
    {
        cmd.CommandText = @"select column_name, table_name from information_schema.columns where table_name in (@namelist)";
        cmd.Parameters.AddWithValue("@namelist",  "'tableOne', 'tableTwo'");

        var reader = cmd.ExecuteReader();

        while (reader.Read())
        {
            var a = reader[0];
            Console.WriteLine(a);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server

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

LINQ:有没有办法为where子句提供带有多个参数的谓词

想知道是否有办法执行以下操作:我基本上想要为具有多个参数的where子句提供谓词,如下所示:

public bool Predicate (string a, object obj)
{
  // blah blah    
}

public void Test()
{
    var obj = "Object";
    var items = new string[]{"a", "b", "c"};
    var result = items.Where(Predicate); // here I want to somehow supply obj to Predicate as the second argument
}
Run Code Online (Sandbox Code Playgroud)

c# linq where

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

关于IEnumerable的延迟执行

在下面的代码中,我理解第二个初始化打印一个"外部"和三个"内部".但是为什么第一个根本不打印,我希望它打印一个"外面".

        DeferExecution a = new DeferExecution(); // prints nothing 
        DeferExecution b = new DeferExecution(null); // print one "outside" and three "inside".

 class DeferExecution
{
    public IEnumerable<string> Input;

    public DeferExecution()
    {
        Input = GetIEnumerable();
    }

    public DeferExecution(string intput)
    {
        Input = GetIEnumerable().ToArray();
    }

    public IEnumerable<string> GetIEnumerable()
    {
        Console.WriteLine("outside");  
        var strings = new string[] {"a", "b", "c"};
        foreach (var s in strings)
        {
            Console.WriteLine("inside");  
            yield return s;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# linq ienumerable deferred-execution

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

如何使用特定的应用程序配置文件

以下代码不起作用。它不会从TestApp.Config文件中获取应用程序设置。你知道为什么吗?我该如何解决?

  public void GetConfig()
  {
     AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"C:\dev\VS\ProofOfConcept\ProofOfConcept\TestApp.config");
     var a = ConfigurationManager.AppSettings;
  }
Run Code Online (Sandbox Code Playgroud)

c# app-config

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