C
C#dusk

❔ accessing object from a class inside of another class

I got this class called "Engine"(image 1) that has the object "isOn" which indicates whether the engine is on or off. I got another class called "Car"(image 2) which consists of several objects as well as on object of type Engine; I'm trying to create a method in class Car that gives me the engine's isOn. I don't know how to refer to it. this is how I tried to do this(image 3) but it doesn't work.
C
canton7384d ago
private bool isOn -- the private there means that only methods inside the Engine class can access it If you want to be able to access it from other classes, use public instead of private
D
dusk384d ago
thank you
D
dusk384d ago
so why does this not work?
C
canton7384d ago
GetIsOn is a method, so you need to invoke it. GetIsOn()
D
dusk384d ago
you're right sorry
J
Jaiganésh384d ago
A property is a better choice here though.
A
Accord383d ago
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.
Want results from more Discord servers?
Add your server
More Posts
❔ QuestionControllerHello, i have a question regarding API structure. I have two classses, Item and Store. I created C❔ Problem Binding to Image SizeI am making an app that displays a series of books. An image and title of the book is to be displaye❔ whats the best site or youtube channel to start learning c#?just downloaded visual studio and wanted to know what would be the best way to learn C#❔ C# MVC - Erroring in VSC not VS2022I'm writing a C# .Net Core 7.0 web application with dapper for my SQL queries. It runs just fine inString Contain issueSo im trying to get a word in a string using Contain but its not getting the word, I havent found a ❔ Catching Exceptions with generic parameters?When adding an entity to the database, i first check if it already exists and if it does I throw an ❔ How should I learn programming?I'm sure this is a common question, but I want to learn game development but am a pretty new C# prog❔ How to properly structure projects in a multi-app MVVM solution?I tend to structure my MVVM projects in the following way: ``` . ├── src/ │ ├── Applications/ │ Sending File and Data to a Minimal API endpointHi. I am using .NET 7, Minimal API and Mailkit. What I want to do is to send an attachment along wi❔ reprotucing the kings pathcan anybody help me fix this code https://paste.mod.gg/sgsvrbaqnmpi/0 ``` the input is number of obs❔ Its there a way to fix this?Hi there, currently I am trying to develop some functions to publish them to azure later, but right ✅ Does this styling code look right?I'm using this code for a simple hover effect. Im wondering if I'm doing this correctly: <Window.Re❔ ?[] operator for dictionariesIs not working. It is explained here. https://learn.microsoft.com/en-us/dotnet/csharp/language-refer❔ IAsyncEnumerable vs List<T> as parameter in methodI have a method that is overloaded and will take in a List<T> or IAsyncEnumerable. The method will b❔ This code is bugged how can i solve it?```LogiwaEntities1 db = new LogiwaEntities1(); ProductData productData = new ProductData✅ How to add hover effect to WPF button elementThis code I'm using isn't working. When I hover over buttons its a lightblue color. <Style with or without refso i learned that in c#(or most oop languages) when you create a method that takes an object as a pa✅ .net trying to find non-existent cs files`Error IDE1100 Error reading content of source file 'D:\Dev\C++\Test\TestCS\obj\Debug\net6.0\.