C
C#2y ago
Str1ke

❔ (Very begginer )

- why is it showing error? :(
23 Replies
Str1ke
Str1keOP2y 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
Str1keOP2y 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
Str1keOP2y ago
Angius
Angius2y ago
Population.BirthCaclulator() that's why
Str1ke
Str1keOP2y ago
On the " Population.BirthCalculator()" yes
Angius
Angius2y ago
BirthCalculator(Population) is what you want
Str1ke
Str1keOP2y ago
Oh
Angius
Angius2y ago
Since it's a regular method, not an extension method
Str1ke
Str1keOP2y ago
It doesn't work
Str1ke
Str1keOP2y 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
Str1keOP2y 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
Str1keOP2y 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
Str1keOP2y 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
Str1keOP2y ago
Angius
Angius2y ago
BirthCalculator BirthCaclulator Spot the difference
Str1ke
Str1keOP2y 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