Click here to Skip to main content
15,891,184 members
Articles / Desktop Programming / Windows Forms

The Model-View-Controller(MVC) Pattern with C#/WinForms

Rate me:
Please Sign up or sign in to vote.
4.94/5 (130 votes)
30 Dec 2013CPOL5 min read 877.1K   49.8K   301  
Briefly and clearly about MVC implementation, without lengthy discussion or minor details
using System;

namespace WinFormMVC.Model
{
    public class User
    {
        public enum SexOfPerson
        {
            Male   = 1,
            Female = 2
        }

        private string    _FirstName;
        public string FirstName 
        {
            get { return _FirstName; } 
            set 
            { 
                 if (value.Length > 50)
                     Console.WriteLine("Error! FirstName must be less than 51 characters!"); 
                 else
                     _FirstName = value; 
            } 
        }

        private string _LastName;
        public string LastName
        {
            get { return _LastName; }
            set
            {
                if (value.Length > 50)
                    Console.WriteLine("Error! LastName must be less than 51 characters!");
                else
                    _LastName = value;
            }
        }

        private string _ID;
        public string ID
        {
            get { return _ID; }
            set
            {
                if (value.Length > 9)
                    Console.WriteLine("Error! ID must be less than 10 characters!");
                else
                    _ID = value;
            }
        }

        private string _Department;
        public string Department
        {
            get { return _Department; }
            set { _Department = value; }
        }

        private SexOfPerson _Sex;
        public SexOfPerson Sex
        {
            get { return _Sex; }
            set { _Sex = value; }
        }


        public User(string firstname, string lastname, string id, string department, SexOfPerson sex)
        {
            FirstName   = firstname;
            LastName    = lastname;
            ID          = id;
            Department  = department;
            Sex         = sex;
        }
    } 

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Canada Canada
Mr.Volynsky Alex is a Software Engineer in a leading software company. Alex is skilled in many areas of computer science. He has over 14 years of experience in the design & development of applications using C/C++/STL, Python, Qt, MFC, DirectShow, JavaScript, VBScript, Bash and of course - C#/.NET.

In addition, Alex is the active member of Intel® Developer Zone (he was awarded by Intel® Green Belt for his active contribution to the Intel Developer Zone community for developers using Intel technology).

Alex is also interested in the Objective-C development for the iPad/iPhone platforms and he is the developer of the free 15-puzzle game on the App Store.

Overall, Alex is very easy to work with. He adapts to new systems and technology while performing complete problem definition research.

His hobbies include yacht racing, photography and reading in multiple genres.
He is also fascinated by attending computer meetings in general, loves traveling, and also takes pleasure in exercising and relaxing with friends.

Visit his C++ 11 blog

Comments and Discussions