I am curious to know why when we are doing P/invoke
the dllimport call is in a “[”
and not just a class or a function
e.g.:
[DllImport("something.dll",....)]
rather than
DllImport("something.dll,....)
or even
DllImport.import(something.dll...)
I do not want to rewrite it, my questions is what does “[” represent or mean ? what is it called in this instance ? Why is it used ?
In this context, it signifies an “attribute”;
DllImportAttribute(MSDN). Simply : it is a syntax already in the language for adding metadata to the code.The language allows you to define your own attributes, or any from libraries. Attributes can be used on assemblies, types, methods, properties, fields, events, parameters, etc – or restricted to a small subset of that.
DllImportAttributeis limited to methods, for example. Most only have meaning when inspected with reflection at runtime, but some re handled directly by the compiler.