【问题标题】:using a SqlConnection in C++ / .NET在 C++/.NET 中使用 SqlConnection
【发布时间】:2011-12-23 14:25:18
【问题描述】:

当我转到SqlConnection 类的MSDN 页面时,它只显示了 C# 和 VB 中的示例。为什么 MSDN 不显示 C++ 示例?

我对 C++ 示例如何解决 C++ 中缺少 using 关键字特别感兴趣。

【问题讨论】:

标签: .net c++ sql-server msdn using-statement


【解决方案1】:

嗯……看了What is the Managed C++ equivalent to the C# using statement之后好像相当于:

using (SqlConnection connection = new SqlConnection(connectionString))
{
    // SqlCommand and so...
}

其实是:

{
  SqlConnection conn(connectionString);

  // SqlCommand and so...
}

这令人印象深刻,因为 C++ 并没有“缺少”using 语句,而是它完全不需要它!我认为 C#/VB 程序员没有充分认识到 C++ 的这种优势(我当然没有:)。

【讨论】:

    猜你喜欢
    • 2015-02-06
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-26
    相关资源
    最近更新 更多