Private list problems
Hello,
I'm trying to search for a Title, which is located in varjeBok.Titel in the list:
But the list is Private (im inside the same class with the search method)
Its giving me the error, "Book.Titel is inaccessible due ro its protection level"
How come I can access the list but not the Title of the object?
How do i fix
12 Replies
Access Modifiers - C# Programming Guide
All types and type members in C# have an accessibility level which controls whether they can be used from other code. Review this list of access modifiers.
- private: The type or member can be accessed only by code in the same class or struct.
thank you, ive read it but didnt find an answer
Just make the property to public
its a requirement for the assignment unfortunately
: - (
As it says.
The type or member can be accessed only by code in the same class or struct.Which means you cannot access private types / members outside of the same class / struct
I am in the same class and i can access the list, but the problem is that I cant specify what element of the object
Book is not in the same class
which means
Titel
is not accessible, because it is private.aaaaaaaaaaaaaaaaaaaaaaaaaah
My private list is in the class Librarian, but the object Book that is saved in the list is in another class
so thats why?
I'm not sure how to fix this though.. Do i need to add something somewhere?
I get it to run this far, but still cant target the varjeBok.Titel
can you show the assignment
so we know the actual requirements
swedish is fine
Thank you, I somehow got it to work with a
inside the book-class
So ill close this 🙂