"using" is a keyword in some programming languages (C++, C#, VB.NET, Haxe)
In the C# language, the using
keyword is employed in two different contexts, as a Directive and a Statement.
The using
directive is used to qualify namespaces and create namespace or type aliases.
using System.Text;
using Project = PC.MyCompany.Project;
The using
statement provides a convenient syntax that ensures the correct use of IDisposable
objects.
using (MyTypeImplementingIDisposable myInstance))
{
// Do something with myInstance
}
Beginning with C# 8.0, you can use the alternative syntax that doesn't require braces
using var myInstance = new MyTypeImplementingIDisposable(...);
// Do something with myInstance
In the VB.NET language the Using
keyword is used only as a Statement and provides the same features as the C# language:
Using sr As New StreamReader(filename)
' read the sr stream
End Using
In Haxe, the using
keyword allows pseudo-extending existing types without modifying their source (syntactical sugar). It is achieved by declaring a static method with a first argument of the extending type and then bringing the defining class into context through using
.
using StringTools;
// works because of the `using`:
var myEncodedString = "Haxe is great".replace("great", "awesome");
// Without the using one should type this:
var myEncodedString = StringTools.replace("Haxe is great", "great", "awesome");
In gnuplot, the using
qualifier allows specific columns in a datafile to be specified, for plotting and fitting.
In C++, the using
keyword can be used in 3 ways;
using declarations
using std::swap;
using directives
using namespace std;
type alias and alias template declaration (since C++11); similar to typedef
template <class CharT> using mystring = std::basic_string<CharT,std::char_traits<CharT>>;