Solved

C# oop Basics

Posted on 2012-04-06
3
433 Views
Last Modified: 2012-04-06
Hello,

i new to c# and programming i have to create something like this:



users user01  = new users("bob", "Piet");   //if no date given it should be set to 2012
users user02  = new users("Roels", "Lut",2003);
users user03  = new users("Adams", "Tom",1989);
users user04  = new users("Dhondt", "Leen",1985);


But i dont knwo how to do this , my class looks like this :
using System;

namespace ConsAppl1TI11
{
    class users 
    {
        public users (string Naam, string voornaam, int jaar)
        {

        }
        public users ()
        {

        }
    }
}

Open in new window


i have to give 3 arguments
0
Comment
Question by:kensy11
3 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 166 total points
ID: 37815813
Homeworks?

you will need another constructor with only 2 arguments that will call the existing one passing 2012 for the last value.
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 167 total points
ID: 37815899
If you are using C# 4.0 (essentially Visual Studio 2010 or better), then you can have a default value for the parameter:

public users (string Naam, string voornaam, int jaar = 2012)
{

}

Open in new window

0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 167 total points
ID: 37815954
In case you need the default value to be the current year instead of a constant.
using System;

namespace ConsAppl1TI11
{
    class users 
    {
        public users (string Naam, string voornaam, int jaar)
        {

        }
        public users (string Naam, string voornaam) : this(Naam, voornaam, DateTime.Now.Year)
        {

        }
        public users ()
        {

        }
    }
}

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question