© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo ago•
11 replies
Vortac

Using IDisposable in private field

I have an an IDisposable object that I would like to turn into a private field:
using var audioEngine = new MiniAudioEngine(44100, Capability.Playback);
using var audioEngine = new MiniAudioEngine(44100, Capability.Playback);

eg:
class SoundEngine {
  private MiniAudioEngine _soundEngine;

  public SoundEngine() {
    _soundEngine = new MiniAudioEngine(44100, Capability.Playback);
}
class SoundEngine {
  private MiniAudioEngine _soundEngine;

  public SoundEngine() {
    _soundEngine = new MiniAudioEngine(44100, Capability.Playback);
}

How can I ensure that the private field uses the
using
using
statement?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

IDisposable and using keyword?
C#CC# / help
2y ago
❔ Destroy objects in CSharp, IDisposable
C#CC# / help
4y ago
IDisposable Constructor Injection
C#CC# / help
12mo ago
IDisposable ownership semantics
C#CC# / help
15mo ago