© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
277 replies
Dinny

are my getters and setters correct?

Before I work on the rest of my code, please let me know if there are any errors in my getters and setters

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



public class Menu
{
private string dishName;
private int dishType, dishPrice;


//def constructor
class Menu() { }

//const with param
public Menu(String dishName, int dishType, int dishPrice)
{
SetName(dishName);
SetType(dishType);
SetPrice(dishType);
}



//GETTERS

/ Returns the name of the dish.
@return: dish name
*/

public void GetName() { return dishName; }


/
Returns the type of dish ordered.
@return: returns either appetizer, entree, or dessert
*/

public int GetType() { return dishType; }

/ Returns the height of the rectangle.
@return: height of the rectangle
*/

public interface GetPrice() { returns dishPrice; }


//SETTERS

/
Updates name of dish.
@param width: the updated dish name
*/

public void SetName(string dishName) { this.Name = dishName; }

/ Updates the type of dish.
@param width: the updated dish type
*/
public void SetType(string dishType) { this.Type = dishType; }

/
Updates the type of dish.
@param width: the updated dish type
*/

public void SetPrice(string dishPrice) { this.Price = dishPrice; }

public override string ToString() { return string.Format(dishName + "(" + dishPrice + ")", GetName(), GetPrice()); }

}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

✅ Importance of getters and setters
C#CC# / help
5mo ago
❔ Difference between public property with protected setters and getters and protected property?
C#CC# / help
3y ago
need help with properties and their setters
C#CC# / help
4y ago
❔ all my inputs are correct and yet they say it is not in a correct format
C#CC# / help
3y ago