C# C# Basics C# Syntax Namespaces

Brooks G
Brooks G
5,273 Points

What does "types" mean in the context of the video -- removing Namespaces before "types" (e.g. Random, Math, Console)?

Thus far, the only discussion of types we've had has been in the previous video, aptly titled "Types." I have a bit of experience with C, so I'm familiar with variables/data types -- the "Types" video is very clear to me.

In the context of this video, are Console/Math/Random considered to be custom data types of sorts, or is "type" a reference to local Namespaces? Or something else?

Thanks!

Brooks G
Brooks G
5,273 Points

I know classes/structs are considered to be complex Data Types of sorts. Perhaps it's just a reference to a specific class (Random, Math, Console) that's defined within one of the Namespaces we're qualifying with the using directive (e.g. "System" in the first example or "Microsoft.VisualStudio.TestTools.UnitTesting," which references several (nested) Namespaces)?

2 Answers

Steven Parker
Steven Parker
177,602 Points

I think you were on the right track the first time. The "types" would not be the namespaces themselves, but the classes contained within them.

Brooks G
Brooks G
5,273 Points

Thanks for the clarification.

I'm aware that nested classes is/are a thing. To my surprise, "Console" is a class rather than a namespace.

In the example, "System.Console.WriteLine," I'm assuming "WriteLine" is a class nested within the "Console" class? I know that "System" is the namespace here.

Brooks G
Brooks G
5,273 Points

Now that I think about it, along with the other example ("System.Math.Round"), WriteLine and Round are obviously methods rather than their own classes (in the other example, System being the namespace, and Math being a class within).

Scratch my previous question. New question: What's up with the difference in notation between .GetType and .WriteLine -- in that one typically precedes the method's argument and the other follows another's argument (I.e. WriteLine() vs. WriteLine().GetType)? I'd assume that it's something specific to GetType and related methods. Is there a reason that GetType doesn't typically precede arguments as well?

Thanks!

Brooks G
Brooks G
5,273 Points

Actually, ignore that question, too -- another video explained that methods such as .GetType can only call on objects (and thus follow), whereas methods like WriteLine can be called by themselves (without objects). If there's any other distinctions worth knowing, I'd be more than interested to find out; otherwise, I think I've got it.

Cheers!

Steven Parker
Steven Parker
177,602 Points

It may have just been a case of "getting ahead of yourself". :wink:

Happy coding!

Brooks G
Brooks G
5,273 Points

Indeed it was (several times over at that!).

Marked it. Cheers!