Don’t Worry, Be Happy!

August 2, 2008

C#: Code for HumanType

Filed under: School, Programming - kAreN maE @ 10:18 pm

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

          
        }

        private void button1_Click(object sender, EventArgs e)
        {
            human x = new human();
            x.Name = textBox1.Text;
            if (comboBox1.SelectedItem.ToString() == "Male")
            {
                x._gender = Gender.Male;
            }
            else
            {
                x._gender = Gender.Female;
            }
            MessageBox.Show(x.Talk());
        }
    }

    }

Human.cs

using System;
using System.Collections.Generic;
using System.Text;
namespace WindowsApplication1
{
    public enum Gender
    {
        Male,
        Female
    }
    public class human
    {
        public human()
        {
            humanCounter++;
        }

        private string name;
        private Gender gender;
        public string Talk()
        {

            return "my name is " + name +" and i am a " + gender +".nCurrent Number of Instance of human" + humanCounter;

        }

        private static int humanCounter = 0;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        public Gender _gender
        {
            get
            {
                return gender;
            }

            set
            {
                gender = value;
            }


        }

    }

}

Comments »

The URI to TrackBack this entry is: http://cutekhartz.blogsome.com/2008/08/02/code-for-humantype/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Alex King