Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi there!
Here is my code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace console_test
{
    class People
    {
       
        static void Main()
        {
            People peo = new People();
            peo.Sumary();
        }

        private int hand;
        private int foot;
        public void hand_no()
        {
            hand = 2;
        }
       
        public void foot_no()
        {
            foot = 2;
        }
       
        public void Summary()
        {
            People peo = new People();
            peo.hand_no();
            peo.foot_no();
            Console.WriteLine("Numbers of hand: ", hand);
            Console.WriteLine("Numbers of foot: ", foot);
            Console.ReadLine();
        }
    }
}


No error was found but the code could not load value 2 (of hand and foot)
Result is:

C#
Numbers of hand:
Numbers of foot:

Press any key to continue...


i don't understand where is the error?
Please help!
Thanks!
Posted
Updated 20-Jul-14 19:57pm
v2
Comments
Kornfeld Eliyahu Peter 21-Jul-14 1:59am    
Oy vey!
Bernhard Hiller 21-Jul-14 2:14am    
Ehm, is that really your account? After 3 years, ...

Try this

C#
public void Summary()
        {
            this.hand_no();
            this.foot_no();
            Console.WriteLine("Numbers of hand: {0}", hand);
            Console.WriteLine("Numbers of foot: {0}", foot);
            Console.ReadLine();
        }
 
Share this answer
 
Hi,

The above mentioned code by Karthik will work. in your code you were trying to update the variables by creating a new object of the people class and the local objects were given for printing the values.

Regards
Anuj Sharma
 
Share this answer
 
C#
static void Main(string[] args)
        {
            People peo = new People();
            peo.Summary(peo);
        }


C#
public void Summary(Program pro1)
       {
         

           pro1.hand_no();
           pro1.foot_no();
           Console.WriteLine("Numbers of hand: {0}", hand);
           Console.WriteLine("Numbers of foot: {0}", foot);
           Console.ReadLine();
       }
 
Share this answer
 

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