Is anyone good with statice modifier?
I need help with my class work about statice modifiers as I'm nearly lost in what I need to do.
37 Replies
that assignment looks extremely straightforward to me
what are you stuck on?
Well on how it works and what statics do
It just doesn't make full sense to me
it tells you exactly what to do
what is the first comment of the instructions you dont undersatand?
I get what to it wants me to do but figuring out how it works doesn't
what do you mean by "figuring out how it works doesn't"? based on what you shared you haven't even started the assignment
start with the first instruction
Define a simple class called MyMathdo that first
Ok so that would simple
That's how far I got
that is a good start but not quite right
you are correctly declaring a class "MyMath" so that is fine, and you made a method "Add" and you made it static as instructed. so all that is good but you have compiler errors inside your Add method
what compiler errors are you getting at the moment? you should see some
well it was compiler erroe CS1955
yep, and what is the message with it
Non-invocable member 'name' cannot be used like a method.
Add = a + B
look at this line specifically. it is not rightOh, wait. Do I need to declare Add as a int?
no
what you are making is a method
methods have a "return"
Oh
you have defined the method to return an
int
but you never return
anything currentlyI see so I show make this?
you do need
return
. but you need to return the sum of a
and b
Which equals add
no
"Add" is the name of the method
you don't need to write "Add" instide the method
you already defined teh method
So name it something else?
you are writing the code that will run when "Add" is called
Then return that vaule?
Methods - C# Programming Guide - C#
A method in C# is a code block that contains a series of statements. A program runs the statements by calling the method and specifying arguments.
look at that documentation and see if you can figure out what you need
So like
closer
what is "Number"?
A int
no it isn't
you jsut wrote "Number"
you didn't write
int Number
C# is a type safe language
when you define a variable, you have to define the type of the variable tooI see
int a;
string b;
object c;
you always have type
then variablename
Alright one more time
that should work 🙂 however you can simplify it to just
return a + b;
you don't need to declare "Number". it is unnecessary bloat. you can do it.. just unnecessaryBut woulden't that be needed when doign the sumtotal?
I'm not sure what exactly you are asking
print(MyMath.Add(10,15));
print(MyMath.Add(13,22));
print(MyMath.Add(56,83));
print(MyMath.sumTotal);
At the end is the sum total of everything we added
Don't we need that Number so we can use it to make equal the sumtotal?
sumTotal
is a seperate member from Add
Your add method should be good
you haven't declared sumTotal
yet
but yes
you will need to add up the sum total
sorry I missed that in your instructions
so
is probably what you want yes, but you need to add "Number" to the sumTotal
before you return
Alright got it, thank you for your help.