?
Solved

C# oop Basics

Posted on 2012-04-06
3
Medium Priority
?
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 664 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 668 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 668 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

650 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