C
C#3y ago
Str1ke

❔ (Very begginer )

- why is it showing error? :(
23 Replies
Str1ke
Str1keOP3y ago
$code
MODiX
MODiX3y 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
Str1keOP3y 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
Angius3y ago
Idk, what's the error?
Str1ke
Str1keOP3y ago
Angius
Angius3y ago
Population.BirthCaclulator() that's why
Str1ke
Str1keOP3y ago
On the " Population.BirthCalculator()" yes
Angius
Angius3y ago
BirthCalculator(Population) is what you want
Str1ke
Str1keOP3y ago
Oh
Angius
Angius3y ago
Since it's a regular method, not an extension method
Str1ke
Str1keOP3y ago
It doesn't work
Str1ke
Str1keOP3y ago
Angius
Angius3y 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
Str1keOP3y ago
:o, what does instance of the encompassing class mean? xd
Angius
Angius3y 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
Str1keOP3y ago
oh But btw, it still doesn't work for some reasons $code
MODiX
MODiX3y 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
Str1keOP3y 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
Angius3y ago
Again, describe "doesn't work"
Str1ke
Str1keOP3y ago
Angius
Angius3y ago
BirthCalculator BirthCaclulator Spot the difference
Str1ke
Str1keOP3y ago
xdd I see it now ahaha thanks
Accord
Accord3y 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.

Did you find this page helpful?