Solved

C# oop Basics

Posted on 2012-04-06
3
436 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

790 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