473,378 Members | 1,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

DO get/set require a semicolen before the braces?

[code]
set
{
this.loc.X = ValueType;
}
Error 1 ; expected Rect.cs 39 16 Lab 4_2
Mar 31 '11 #1
3 1530
VijaySofist
107 100+
Hi,

Please post your full code here.

Please find the Property Sample Below.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2.  
  3. public class Customer
  4. {
  5.     private int m_id = -1;
  6.  
  7.     public int ID
  8.     {
  9.         get
  10.         {
  11.             return m_id;
  12.         }
  13.         set
  14.         {
  15.             m_id = value;
  16.         }
  17.     }
  18.  
  19.     private string m_name = string.Empty;
  20.  
  21.     public string Name
  22.     {
  23.         get
  24.         {
  25.             return m_name;
  26.         }
  27.         set
  28.         {
  29.             m_name = value;
  30.         }
  31.     }
  32. }
  33.  
  34. public class CustomerManagerWithProperties
  35. {
  36.     public static void Main()
  37.     {
  38.         Customer cust = new Customer();
  39.  
  40.         cust.ID = 1;
  41.         cust.Name = "Amelio Rosales";
  42.  
  43.     Console.WriteLine(
  44.             "ID: {0}, Name: {1}",
  45.             cust.ID,
  46.             cust.Name);
  47.  
  48.         Console.ReadKey();
  49.     }
  50. }
  51.  
Regards
Vijay.R
Mar 31 '11 #2
Here, even though i know there are still other things wrong with some of this code. The error messages keep asking for semicolons after the get and set except for getFillColor

[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Lab_4_2
{
class Rect
{
Point loc;
Size dimentions;
Color fill;
public Rect(int x, int y, int width, int height)
{
...
}
public void Draw(Graphics g)
{
...
}
public Color getFillColor
{
get { return this.fill; }
set { this.fill = Color; }
}
public static int X()
{
get;
{
return this.loc.X;
}
set
{
this.loc.X = ValueType;
}
}
Mar 31 '11 #3
GaryTexmo
1,501 Expert 1GB
You've got brackets for your X property. You don't need those. You also don't need a semi-colon after get since you're implementing the method. The only time you don't need this is when you use auto-implemented properties, which is when you don't define the method.

Example:
Expand|Select|Wrap|Line Numbers
  1. public class Person
  2. {
  3.   private int m_age;
  4.  
  5.   // This is an auto-implemented property (requires VS 2008 and up
  6.   public string Name { get; set; }
  7.  
  8.   // This property is manually implemented
  9.   public int Age
  10.   {
  11.     get { return m_age; }
  12.     set { m_age = value; }
  13.   }
  14. }
Also, in the set for X, you're assigning the X property of the location variable to ValueType. In C# the correct keyword is value, as in the above example.

You can look at my examples, those posted by Vijay, and your own getFillColor property for correct examples of how properties are used.

Good luck!
Mar 31 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

97
by: Kjetil Torgrim Homme | last post by:
often when re-factoring code, I need to change the indent level of some chunk of code. due to the lack of an end marker, my Emacs has to use heuristics when re-indenting, and this will...
16
by: Jason | last post by:
Programming recently I was the habit of leaving out the braces on if statements if the branch only applied to a single line, assuming it would all work and be equivalent to "if(condition) {...
7
by: John Bailo | last post by:
how come I can say: if() statement; else statement; but I cannot say try statment; catch() statement;
14
by: Andrew Bullock | last post by:
I thought the two bits of code should be the same? They aren't evaluating the same for me .... Can someone tell me why please? Thanks Andrew
12
by: reycri | last post by:
While the following is allowed: if (a == b) SomeFunction(); else OtherFunction(); The following is not: try
2
by: mauricioarango | last post by:
Hi everybody, I'm a PHP beginner, so please forgive me for this question. I am working on code someone else wrote a long time ago. The code was written without curly braces in many places, which...
22
cat
by: Jag | last post by:
I've read parts of K&R's ANSI C v2 and this is what their cat looked like but when I compared the speed of this code to gnu cat, it seems very slow. How do I optimize this for greater speeds? is...
38
by: tshad | last post by:
In VS 2008, why doesn't ToString require "()". If I have Option Strict On on why can I do both: selectedIndex.ToString() selectedIndex.ToString or sQuery =...
2
by: Denny | last post by:
I'm going from VB.net. Is there a way to have VS automatically add braces to methods? Also in VB, you do not need to add () for a method or function that does not need parameters. Is there a way...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.