CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Posts
    3

    learning C# help

    Using .Net Framework 4.0

    I am brand new 2 programming and learning how to write programs in C# while practicing some exercise I'm getting this error:

    Properties.Dog.Color.get' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors. H:\Documents and Settings\noname\Desktop\C# Oreilly\ConsoleApplication1\ConsoleApplication2\Program.cs 17 13 ConsoleApplication2

    I cannot seem to figure it out

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace properties
    {
    
        public class Dog
        {
            private int weight;
            private string color;
    
         public string Color
               {
                 get
                 {
                   return color;
                 }
                 set
                 {
                  color = value;
                 }
               }
    
         public Dog(int myWeight, string myColor)
         {
             weight = myWeight;
             color = myColor;
         }
        }
    
        public class Tester
        {       
                    static void Main( )
                        {
                            
                        }
         }
    }

  2. #2
    Join Date
    Oct 2005
    Location
    Seattle, WA U.S.A.
    Posts
    353

    Re: learning C# help

    I dunno ... works for me as a console application

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.Console.WriteLine(args.Length);
    
                string color;
                Dog fido = new Dog(12, "red");
                fido.Color = "blue";
                color = fido.Color;
            }
        }
    
        public class Dog
        {
            private int weight;
            private string color;
    
             public string Color
               {
                 get
                 {
                   return color;
                 }
                 set
                 {
                  color = value;
                 }
               }
    
             public Dog(int myWeight, string myColor)
             {
                 weight = myWeight;
                 color = myColor;
             }
        }
    
    
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured