❔ Whats the difference between classes and public classes?
Tried looking at Microsoft docs earlier but the don't really answer the question.
I already know what assess modifiers are, but how to do they affect classes?
23 Replies
by default it's internal
ik
It effects whether other code can make use of the class. For instance, if you make a class library and publish it...and I consume that class library...my code can only use public classes
In that library
so what if i had 2 different classes in 2 different files in the same project, can the normal class inherit from the public one
Sure
If the public class is not marked sealed
but what about assemblies?
i dont know much about them
The internal keyword restricts access to code in the same assembly
oh
wait when using public classes from another assembly do you need to use refrences
im not sure how to add one in visual studio
Yes, you need some kind of reference to that assembly...usually a PackageReference for code from some third party or ProjectReference for code you own
oh ok
do projects usually need multiple assemblies?
because from what i know you cant use private/ private protected acsess modifiers within a namespace
I'm not sure what that has to do with multiple assemblies
public classes can be assessed by different assemblies within the same solution, no?
If there is a project reference
yeah i just made one now lol
Just a note about terminology, a solution contains multiple projects, each project is one assembly, and each assembly contains multiple types (like classes)
im struggling to create a refrence from the program in assembly 1 to the other program in assembly 2
by any chance do you know how to do this
im trying to use the public class within the program in assembly 1 in the program in assembly 2
^assembly#1
Right click on the Dependencies in project 2, then add project reference (I think it's called that), then select project 1
ive done that but how do i use the public class in the program now?
Add a
using CSharp;
at the top of your fileoo no errors yet hold on tho
oml it worked
all of this just to figure out how public classes work 😮💨
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.