-
April 13th, 2014, 12:47 PM
#1
New to C#! Arguments to Private Variables
Hello, right now i'm learning C# and I need some one to clarify what my teachers trying to say. We have to make a simple score sheet which I did but not the way he wanted, we're suppose to have Player One with x points which I did but this is the part I don't get.
3 setName
argument: name
argument type: string
return type: nothing
Method sets the value of the private variable Name.
You are suppose to assign the name arg to the private variable]
If private string Name; is already defined and in the setName(){} wouldn't Name = "Player One" suffice? From my understanding Name is already set as a string before adding it in the function, so the argument would be: Name = "Player One", because there's no return for setName(){} it's a void. Nothing was defined if the function was suppose to be public or private so I made it public. And "Player One" would be the value for Name.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ScoreSheet
{
class Player
{
private string Name;
private float Score;
public void setName()
{
Name = "Player One";
}
public string getName()
{
return Name;
}
public float addPoints(float points)
{
Score = points;
return points;
}
public float getPoints()
{
return Score;
}
}
class Program
{
static void Main(string[] args)
{
Player play = new Player();
play.setName();
play.getName();
Console.WriteLine("Player One, your points are: " + play.addPoints(10));
play.getPoints();
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|