I need to create a program where the user can fill in 4 names with 1 programming specialty.
I created 2 classes and a separate enum file.
I can't get the List<Programmeur>
programmeurs = new List<Programmeur>(); get to start an instance with the Programmer class contructor so that 4 names are asked and being printed.
I hope someone can give me some solution or help so i can understand it. I included the files in a rar. Thx.
Loading
Bechir BejaouiPosted Sep 28, 2010, 6:15 AM
I wrote an article about the difference between the classes and strutures may it helps you have a primary idea about the main difference between structure and class
http://www.c-sharpcorner.com/UploadFile/yougerthen/403022009052133AM/4.aspx
It's so popular that they translate it to chinese. I invite you to have a look
Here is the chinese version of my article
http://www.agiledon.com/post/2009/03/Structure-vs-Class.html
hah hahahaahahahaahaaaha!!!!!!!!!!!!!!!
If you have any question about C sharp basic or anvanced then dont hesitate to ask me : )
Good luck
encPosted Sep 27, 2010, 5:38 PM
The language i used in the files is dutch, it sounds alot like german and adopted some english and french. Personally i dont think it's really worth learining dutch since it isn't much use outside the Netherlands. I hope i can speak c# well some day :)
Bechir BejaouiPosted Sep 23, 2010, 4:35 PM
For instance, I have a question form a ceriousity and nothing else. I know german language and I know french too very well I see that the language that you use is a mixture of the both, I mean French and Germain. This is the first time that I see this. Is it the Francais-allemand language?
encPosted Sep 23, 2010, 3:50 PM
List<Programmeur> programmeurs = new List<Programmeur>();
Program.cs
using System;
using Opdr2;
public enum Specialiteit
{
Java = 1,
Csharp,
HTML,
PHP,
}
class Start
{
public static void Main(string[] args)
{
Team myTeam = new Team();
for (int aantProg = 0; aantProg < 4; aantProg++)
{
Console.Write("Geef de naam van de programmeur : ");
string naampje = Console.ReadLine();
Console.WriteLine("Geef de specialiteit van de programmeur.");
Console.Write(@"
1 = JAVA,
2 = Csharp
3 = HTML
4 = PHP
Kies een nummer (1, 2, 3 of 4): ");
// laat de gebruiker een (int) waarde invoeren
string spec = Console.ReadLine();
int invoer = Int32.Parse(spec);
// do de cast van int naar Specialiteit enum type
Specialiteit mySpecialiteit = (Specialiteit)invoer;
string specialiteit = mySpecialiteit.ToString();
Console.WriteLine("");
myTeam.addProgrammeur(new Programmeur(mySpecialiteit, naampje));
}
myTeam.printTeam();
Console.ReadLine();
}
}
programmeur.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Opdr2
{
public class Programmeur
{
public Specialiteit specialiteit;
public string naam;
public Programmeur(Specialiteit spec, string naam)
{
specialiteit = spec;
this.naam = naam;
}
public void print()
{
Console.WriteLine("Naam programmeur: " + naam + " , specialiteit: " + specialiteit);
}
}
}
Team.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Opdr2
{
public class Team
{
List
public void addProgrammeur(Programmeur prog)
{
programmeurs.Add(prog);
}
//Loop through List with for
public void printTeam()
{
for (int aantProg = 0; aantProg < programmeurs.Count; aantProg++)
{
programmeurs[aantProg].print();
}
Console.WriteLine("Aantal programmeurs: {0} ", programmeurs.Count);
Console.ReadLine();
}
}
}
Bechir BejaouiPosted Sep 20, 2010, 6:42 PM
If you want to do a programm like that then follow those steps
Create a Programmeur class like this
public class Programmeur
{
public string Name{get;set;}
//Put the other properties here including
public Specialiteit Specialiteit{get;set}
public override string ToString()
{
switch(Specialiteit)
{
Case Specialiteit.Csharp:
return string.format("{0} est un programmeur C sharp",Name);
break;
Case Specialiteit.Csharp:
return string.format("{0} ist ein software entwickler der in Java Specializiert ist",Name);
break;
//Und so weiter zu mit dem anderen case bis zu
default:
return string.format("{0} is specialized in other programming language that is not precized yet in the enum",name) ;
break;
}
}
}
Go to the main and add the following code
List<> list = new List<>();
Programmeur instance = new Programmeur();
int option = 1;
for(i=0;i<4;i++)
{
Console.WriteLine("Faite entrer le nom svp");
instance.Name = Console.ReadLine();
Console.WriteLine("Fur Csharp bite nehmen 1, Fur Java bite nehmen 2....");
option = System.Convert.ToIn32(Console.ReadLine());
switch(option)
{
case 1:
instance.Specialiteit = Specialiteit.Csharp;
break;
case 1:
instance.Specialiteit = Specialiteit.Java;
break;
default:
break ;
}
list.add(instance);
}