Keyword "using" can only be used with classes implementing IDisposable Interface; your class don't.
compiler to remind when "using" key is not used. and program get exception .
That's not possible.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi dear form users
I have a question. ı want to make a create instanse of my costumized class but I want this action to be real using only the word "using". compiler to remind when "using" key is not used. and program get exception .
public class Deneme
{
public int ID { get; set; }
public int Name { get; set; }
public int Surname { get; set; }
}
static void Main()
{
using (Deneme d = new Deneme()) // My costume class using only this method
{
// Operation
}
}
static void Main()
{
Deneme d = new Deneme(); // Compiler get an error when didnt used using keyword
}
I don't want you to get an example without using the using keyword
Keyword "using" can only be used with classes implementing IDisposable Interface; your class don't.
compiler to remind when "using" key is not used. and program get exception .
That's not possible.
I believe the compiler error is telling you that it cannot find the Deneme class and is asking if you need to make a reference or add a using statement with the namespace of the type to the top of the code file. Visual Studio shows a help icon that lists possible code fixes for the this fundamental programming construct.
For example.
using Namespace.Deneme;
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/namespace
Check a different approach:
static void Main()
{
MyClass.PerformOperation(some parameters);
}
where PerformOperation is a static function of static class. Inside this function you can use your disposable internal classes and the using statement. You and other people that call this function will not have to remember to use using.