0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[メモ] C#のusingステートメントの使い方

Posted at

はじめに

C#初心者の私がドメイン駆動設計入門書を読んでいて躓いたので調べた。

リソースの開放

C#では外部リソースとつながったあとは、usingステートメントを用いることでソースが占領しているメモリを開放しメモリリークを防いでいる。

public class UserRepository : IUserRepository
{
.
.
.
  public void Save(User user)
  {
    using (var connection = new SqlConnection(connectionString))
    using (var command = connection.CreateCommand())
    {
    .
    .
    .
    }
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?