Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 30-Jul-16 6:12am
Comments
Karthik_Mahalingam 30-Jul-16 12:12pm    
Homework.
Read the below two docs , you will find the answer for sure.
c# variables/[^]
Methods (C# Programming Guide)[^]

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.
 
Share this answer
 
You're close...but not quite there. And it's pretty obvious when you see it written down.
C#
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.
 
Share this answer
 
Comments
Member 12661694 30-Jul-16 12:34pm    
thank you! i know how to read code-however it is difficult for me to write code following instructions as I am still learning!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900