C
C#2y ago
Str1ke

❔ (Very begginer )

- why is it showing error? :(
23 Replies
Str1ke
Str1ke2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Str1ke
Str1ke2y ago
static void Main(string[] args)
{
Actor[] actArr = new Actor[37];
Console.WriteLine("Enter the Population, that you want to see how many they will be in a year");
double Population = double.Parse(Console.ReadLine());
Console.WriteLine("The population will be: " + Population.BirthCaclulator());
}
public double BirthCaclulator(double Population)
{
Population /= 1000;
return Population * 18 - Population * 7;
}
static void Main(string[] args)
{
Actor[] actArr = new Actor[37];
Console.WriteLine("Enter the Population, that you want to see how many they will be in a year");
double Population = double.Parse(Console.ReadLine());
Console.WriteLine("The population will be: " + Population.BirthCaclulator());
}
public double BirthCaclulator(double Population)
{
Population /= 1000;
return Population * 18 - Population * 7;
}
Angius
Angius2y ago
Idk, what's the error?
Str1ke
Str1ke2y ago
Angius
Angius2y ago
Population.BirthCaclulator() that's why
Str1ke
Str1ke2y ago
On the " Population.BirthCalculator()" yes
Angius
Angius2y ago
BirthCalculator(Population) is what you want
Str1ke
Str1ke2y ago
Oh
Angius
Angius2y ago
Since it's a regular method, not an extension method
Str1ke
Str1ke2y ago
It doesn't work
Str1ke
Str1ke2y ago
Angius
Angius2y ago
Ah, it's not static so you'd need an instance of the encompassing class An easy fix is making the method static
Str1ke
Str1ke2y ago
:o, what does instance of the encompassing class mean? xd
Angius
Angius2y ago
class Foo
{
public int Bar()
{
return 2;
}
}
class Foo
{
public int Bar()
{
return 2;
}
}
you'll need
var f = new Foo();
var num = f.Bar();
var f = new Foo();
var num = f.Bar();
to call it An instance of the class the method is inside of
Str1ke
Str1ke2y ago
oh But btw, it still doesn't work for some reasons $code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Str1ke
Str1ke2y ago
static void Main(string[] args)
{
Actor[] actArr = new Actor[37];
Console.WriteLine("Enter the Population, that you want to see how many they will be in a year");
double Population = double.Parse(Console.ReadLine());
Console.WriteLine("The population will be: " + BirthCalculator(Population));
}
public static double BirthCaclulator(double Population)
{
Population /= 1000;
return Population * 18 - Population * 7;
}
static void Main(string[] args)
{
Actor[] actArr = new Actor[37];
Console.WriteLine("Enter the Population, that you want to see how many they will be in a year");
double Population = double.Parse(Console.ReadLine());
Console.WriteLine("The population will be: " + BirthCalculator(Population));
}
public static double BirthCaclulator(double Population)
{
Population /= 1000;
return Population * 18 - Population * 7;
}
Angius
Angius2y ago
Again, describe "doesn't work"
Str1ke
Str1ke2y ago
Angius
Angius2y ago
BirthCalculator BirthCaclulator Spot the difference
Str1ke
Str1ke2y ago
xdd I see it now ahaha thanks
Accord
Accord2y 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
✅ mistery -foreach cycle executed three times for no apparently reasonHere is the code. I checked more and more times for errors, I always putted some breakpoint in orde❔ VS 2022 debugger ArgumentNullException not showing ParamName in quick info tooltipThis is mostly a QoL problem. I'm not sure if it's a bug or a problem with my configuration. Visua❔ Problem CanUseCmdhttps://media.discordapp.net/attachments/169726586931773440/1064902725231460443/image.png❔ Need Help with httpclient Async stream readingI do not have much experience with reading data from an stream endpoint (I am sure there is better n❔ Is there a version of matrix of which sqlpackage.exe goes with which version of sql server?Looking for a link that can tell me which goes with which because I need to find sqlpackage.exe for ❔ XML serialization - internal XML elementHow can I get rid of the internal XML of the Value element? Should I add some attribute on field in ❔ Rx.NET issueThis is a minimal reproducible example of request/response model (like HTTP) but over websockets. ❔ trying to detect when the enter key is pressedusing ReadKey() but i dont know what the Enter key is to put in here❔ How to disable an Exception Filter for a specific Action in ASP.NET Core?Hi dear friends, I hope you doing well, I'm working on an `ASP.NET Core 7` project. I created the fo❔ ✅ is it possible to ''lock'' a var after the first assignment?I'm making some base practice with C# with some exercises. I completed the first one, and it have a