❔ Using method in other class
In my program I have a method aantaluur() it is in the class Periode. I have some error but dont know how to fix it. The main class can't be changed because the task was to make the classes for this main.
21 Replies
How can I share my code again?
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/$codegif
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
What error are you receiving?
BlazeBin - duvxayoocxyn
A tool for sharing your source code with the world!
tried using static but than he doesn't accept the properties
You need to create an instance of that class to use its method. Otherwise, you can mark the method as static
That'd allow you to use it without creating an instance
Static Classes and Static Class Members - C# Programming Guide - C#
Static classes cannot be instantiated in C#. You access the members of a static class by using the class name itself.
So I need to make NettoVerhuurPeriode static
You are missing the
new
keyword to create a new instance of of your class
I'm unable to open the blazebin at this momentOk no problem 😄
var myInstance = new MyClass();
myInstance.NonStaticMethod();
I think I fixed it
I wrote Periode.Aantaluur() it had to be AantalUur()
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.