Solved

C# oop Basics

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

Assisted Solution

by:Éric Moreau
Éric Moreau earned 166 total points
Comment Utility
Homeworks?

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

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 167 total points
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now