Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
QuestionChart Generating Tool Pin
gopichand.n26-Apr-16 23:45
gopichand.n26-Apr-16 23:45 
QuestionRe: Chart Generating Tool Pin
Richard MacCutchan26-Apr-16 23:57
mveRichard MacCutchan26-Apr-16 23:57 
AnswerRe: Chart Generating Tool Pin
gopichand.n27-Apr-16 1:56
gopichand.n27-Apr-16 1:56 
GeneralRe: Chart Generating Tool Pin
Richard MacCutchan27-Apr-16 2:09
mveRichard MacCutchan27-Apr-16 2:09 
GeneralRe: Chart Generating Tool Pin
gopichand.n3-May-16 1:39
gopichand.n3-May-16 1:39 
GeneralRe: Chart Generating Tool Pin
Richard MacCutchan3-May-16 2:34
mveRichard MacCutchan3-May-16 2:34 
QuestionC# Pin
Member 1248659326-Apr-16 7:45
Member 1248659326-Apr-16 7:45 
AnswerRe: C# Pin
OriginalGriff26-Apr-16 8:30
mveOriginalGriff26-Apr-16 8:30 
Basically, don't.
Look at your code for the Data constructor (I'll rip out some of it top make it clearer):
C#
while (true)
{
    ...
    if (entry == 1)
    {
        ...
    }
    else if (entry == 2)
    {
    }
    else
    {
        ...
    }
    break;
}
Which means that regardless of what path you take though the if, you will always exit your loop at the end of the first iteration. So why is the loop there at all?

But there are more fundamental things: why are you getting the values inside the class constructor at all? That "locks" the class to always only work from the Console, you can't create an instance from data he entered last time if you save it. That's bad design - there is no good reasond for the Data class to have any idea where the data comes from. In fact is much, much better from an OOPs standpoint if the class has no idea where data comes from!

But your Data class is not a "real" class - it's just code you will call from your main method by a silly mechanism.
Classes aren't there to act as "super containers" for blocks of procedural code - they are supposed to be there to contain the data and it's related methods so each instance can work on it's own data.
For example, a simple class:
C#
public class User
    {
    private string name;
    private string hairColour;
    private DateTime dateOfBirth;
    public User(string name, string hairColour, int year, int month, int day)
        {
        this.name = name;
        this.hairColour = hairColour;
        dateOfBirth = new DateTime(year, month, day);
        }
    public int GetAge()
        {
        DateTime start = dateOfBirth;
        DateTime end = DateTime.Now.Date;
        int days = end.Day - start.Day;
        if (days < 0)
            {
            end = end.AddMonths(-1);
            days += DateTime.DaysInMonth(end.Year, end.Month);
            }
        int months = end.Month - start.Month;
        if (months < 0)
            {
            end = end.AddYears(-1);
            months += 12;
            }
        int years = end.Year - start.Year;
        return years;
        }
    public string GetDetails()
        {
        return string.Format("{0} ({1}) is now {2}", name, hairColour, GetAge());
        }
    }

You create users thus:
C#
User mike = new User("Mike Smith", "Blonde", 1990, 11, 14);
User joe = new User("Joe Ninety", "Mousey", 1983, 2, 1);
And the class then handles all the work itself:
C#
User mike = new User("Mike Smith", "Blonde", 1990, 11, 14);
User joe = new User("Joe Ninety", "Mousey", 1983, 2, 1);
Console.WriteLine(mike.GetDetails());
Console.WriteLine(joe.GetDetails());

And it will print:
Mike Smith (Blonde) is now 25
Joe Ninety (Mousey) is now 33

The User class is independent of the input and output mechanism, it just handles users and their data.

Do you see the difference between that and what you are trying to do?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

SuggestionRe: C# Pin
Sascha Lefèvre26-Apr-16 9:23
professionalSascha Lefèvre26-Apr-16 9:23 
GeneralRe: C# Pin
Pete O'Hanlon26-Apr-16 9:31
mvePete O'Hanlon26-Apr-16 9:31 
GeneralRe: C# Pin
Matt T Heffron26-Apr-16 10:22
professionalMatt T Heffron26-Apr-16 10:22 
GeneralRe: C# Pin
Pete O'Hanlon26-Apr-16 10:58
mvePete O'Hanlon26-Apr-16 10:58 
GeneralRe: C# Pin
Sascha Lefèvre26-Apr-16 12:01
professionalSascha Lefèvre26-Apr-16 12:01 
SuggestionRe: C# Pin
Richard Deeming27-Apr-16 1:47
mveRichard Deeming27-Apr-16 1:47 
GeneralRe: C# Pin
Sascha Lefèvre27-Apr-16 1:49
professionalSascha Lefèvre27-Apr-16 1:49 
QuestionCapture exceptions and handle those in my custom error handler Pin
Member 1204569226-Apr-16 5:37
Member 1204569226-Apr-16 5:37 
AnswerRe: Capture exceptions and handle those in my custom error handler Pin
Eddy Vluggen26-Apr-16 5:48
professionalEddy Vluggen26-Apr-16 5:48 
QuestionStudent admin management system C# console Pin
Member 1248538426-Apr-16 5:19
Member 1248538426-Apr-16 5:19 
QuestionRe: Student admin management system C# console Pin
Richard MacCutchan26-Apr-16 5:26
mveRichard MacCutchan26-Apr-16 5:26 
AnswerRe: Student admin management system C# console Pin
Eddy Vluggen26-Apr-16 5:55
professionalEddy Vluggen26-Apr-16 5:55 
GeneralRe: Student admin management system C# console Pin
Member 1248538426-Apr-16 7:48
Member 1248538426-Apr-16 7:48 
QuestionRe: Student admin management system C# console Pin
Eddy Vluggen26-Apr-16 8:25
professionalEddy Vluggen26-Apr-16 8:25 
GeneralRe: Student admin management system C# console Pin
Matt T Heffron26-Apr-16 7:54
professionalMatt T Heffron26-Apr-16 7:54 
AnswerRe: Student admin management system C# console Pin
Member 1507847221-Feb-21 3:00
Member 1507847221-Feb-21 3:00 
AnswerRe: Student admin management system C# console Pin
Member 1507847221-Feb-21 3:12
Member 1507847221-Feb-21 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.