In “Demo: Classes” lesson of a C# course I am not getting the same result Mosh got in the video.
Adding “public” access modifier to a class of a different namespace doesn’t have any effect for me - I can access a class from a different namespace anyway, without adding “public” access modifier.
But in the tutorial Mosh could not access the class before specifying that class as “public”.
I am curious, why the behaviour was different in the lesson video?
I don’t see a “Demo: Classes” lesson in the C# course so I don’t know the project you are talking about.
If you don’t have an explicit access modifier on your class the default is
internal meaning you can access the class from within the same assembly. If you put it into a different assembly than the consumer you need to make it
public to be accessible.
It is Part 1 of Ultimate C# Series. Here is the link to the lecture, just in case. Discussion of “public” keyword starts at 4:55.
All makes sense, that is also what official documentations is saying.
The question is not critical, I am just curious why the result is different.
That video is from 2015 and I don’t think that Mosh isn’t able to access the class but that his tooling (Visual Studio, ReSharper) isn’t suggesting the class. If he had imported the namespace he would have been able to access the class.
As you see - the tooling has evolved since 2015. Mosh even uses ReSharper to import a namespace - nowadays Visual Studio is able to do that on it’s own.
I see, I was suspecting it might be something to do with intellisense, but I wasn’t sure, thanks a lot!