C#: Cannot locate System libraries -
i have looked in regedit , found running .net version 4.5.1 , therefore libraries after should available me.
i try include namespaces:
using system.io.memorystream; using system.media.soundplayer;
however vs complains namespaces not exist.
the reference pages memorystream , soundplayer dictate these should available in version of .net. how can fix this?
you confusing class names , namespaces , possibly using
directive using
statement.
system.io
namespace. it's grouping construct used logically group classes , structs , avoid name clashes. system.io.memorystream
class inside system.io
namespace.
if want use memorystream
can either:
var ms = new system.io.memorystream(...);
or, avoid verbosity of specifying namespace (a full qualified name), can use using
directive:
using system.io;
and can use class name:
var ms = new memorystream(...);
you can think of using
directive telling compiler search paths use when looking class. if ask memorystream
it's going first in current namespace class named memorystream
, if doesn't find one, it's going in namespaces have been imported using
directive (in vb.net, believe equivalent directive called imports
which, arguably, makes more sense, there go). if still doesn't find memorystream
class you'll compile time error.
note: you'll compile time error if finds more 1 memorystream
because won't stop on first 1 - classes need unambiguous. , reason not stuff lot of unneeded using
directives @ top of every .cs
file. memorystream
isn't particularly problem here (i think it's memorystream
in bcl), class in system.io
path
. there several classes called path
in bcl (there 1 under system.windows.shapes) , without namespaces they'd nightmare use.
now, confusion might come using
statement used classes implement idisposable
ensure disposed. memorystream
implement idisposable
you'll see things like:
using (var ms = new memorystream(...)) { // code here }
or, if haven't used using
directive declare namespace:
using (var ms = new system.io.memorystream(...)) { // code here. }
which looks lot trying using
directive.
when looking @ class in msdn there 2 important things need for:
namespace: system.io
assemblies: mscorlib (in mscorlib.dll) system.io (in system.io.dll)
namespace tells need include either in using
directive or part of qualified class name in order use class. assemblies part tells assemblies need add references projects in order able use classes. in case memorystream
part of core libraries, aren't not have reference required assemblies.
Comments
Post a Comment