将字符串参数分配给私有字符串字段(coursename) [英] Assign the string parameter to the private string field (coursename)
问题描述
私人字符串课程名称
{
}
setName(字符串)
{
}
这些是我的指示:< br $> b $ b
1)创建私人字符串字段
示例:
私有字符串courseName
2)使用字符串参数创建名为setName的方法。在方法体内 - 将字符串参数分配给私有字符串字段(courseName)
我尝试过:
我试过阅读我的书并观看视频。我仍然非常困惑。
private string courseName
{
}
setName(string)
{
}
These were my instructions:
1) create a private string field
example:
private string courseName
2) create a method named setName with a string parameter. Inside the method body-assign the string parameter to the private string field (courseName)
What I have tried:
I have tried reading through my book and looking at videos. I'm still very much confused.
推荐答案
courseName
应该是一个字段而不是方法。请参阅访问者(C#) [ ^ ]。您也可以找到 Charles Petzold的.NET Book Zero [ ^ ]对初学者很有用。
courseName
is supposed to be a field not a method. See Accessors (C#)[^]. You may also find .NET Book Zero by Charles Petzold[^] useful for beginners.
你很接近......但不完全在那里。当你看到它写下来时很明显。
You're close...but not quite there. And it's pretty obvious when you see it written down.
public class MyClass
{
private string courseName;
...
public void setName(string name)
{
courseName = name;
}
}
现在看看作业,你应该看看每个位与问题的关系。
Now look at the homework and you should see how each "bit" relates to the question.
这篇关于将字符串参数分配给私有字符串字段(coursename)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!