C
C#12mo ago
divolo

❔ new to programming and can't figure out

i want to create an appointment scheduler that let's the user create view update and delete but can't figure out how using System; using System.Data; namespace appointment { class Program { static void Main(string[] args) { bool showMenu = true; while (showMenu) { showMenu = Mainmenu(); } } private static bool Mainmenu() { Console.Clear(); Console.WriteLine("menu"); Console.WriteLine("1 )schedule appointment"); Console.WriteLine("2 )view appointment"); Console.WriteLine("3 )update appointment"); Console.WriteLine("4 )delete appointment"); Console.WriteLine("5 )exit"); Console.Write("\r\nselect an option:"); switch (Console.ReadLine()) { case "1": return true; case "2": return true; case "3": return true; case "4": return true; case "5": return false; default: return true; } } private static void } }
27 Replies
boiled goose
boiled goose12mo ago
ok, but any more details? where do you want to keep your data?
Pobiega
Pobiega12mo ago
@divolo more details needed. Where are you stuck? What have you tried? How do you want to persist (store) your data?
divolo
divolo12mo ago
i don't know how to store data the user inputs nor how to let the user delete any changes they want
Pobiega
Pobiega12mo ago
okay, well, you'll likely want to have a list of appointments in your program, and then save/load that to/from a file on disk as needed step 1 might be to define what an Appointment class looks like
divolo
divolo12mo ago
like this? class appointment { public string title; public string date; public string time; public string loation; }
Pobiega
Pobiega12mo ago
Something like that, but those are fields and should probably be properties in an idiomatic C# program
divolo
divolo12mo ago
like this public string? Title { get => title; set => title = value; } public string? Date { get => date; set => date = value; } public string? Time { get => time; set => time = value; } public string? Location { get => location; set => location = value; }
SinFluxx
SinFluxx12mo ago
should just be able to do public string? Title { get; set; }
divolo
divolo12mo ago
{ internal class Appointment { public string? title; public string? date; public string? time; public string? location; public string Title { get; set; } public string Date { get; set; } public string Time { get; set; } public string? Location { get; set; }
} right?
SinFluxx
SinFluxx12mo ago
don't need all your public string? title;
divolo
divolo12mo ago
public string? Title { get; set; } public string? Date { get; set; } public string? Time { get; set; } public string? Location { get; set; } or should i delete the ?
SinFluxx
SinFluxx12mo ago
you can remove it, but you'll then get a compiler warning, this explains it a bit more and what options you have, but don't worry if it's a bit much right now! https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/nullable-warnings#nonnullable-reference-not-initialized
Resolve nullable warnings
Several compiler warnings indicate code that isn't null-safe. Learn how to address those warnings by making your code more resilient.
SinFluxx
SinFluxx12mo ago
if you do remove the ? you'll still be able to carry on with your program without doing anything about it, just that if you then forget to assign a value to one of those properties you'll get an exception
divolo
divolo12mo ago
so if i remove it it won't change anything right?
SinFluxx
SinFluxx12mo ago
nothing will "change" exactly, no, you'll see a warning under those lines in visual studio telling you that you haven't given those properties a value but at that point it's just a warning
divolo
divolo12mo ago
so i've defined appointment how do i store what the user inputs in the appointment? sorry if my english isn't clear english isn't my first language
SinFluxx
SinFluxx12mo ago
well you'll have to receive, Read, data from the user, make an Appointment from it, and store it in a file/database/whatever you're using
Pobiega
Pobiega12mo ago
I recommend making a public Appointment CreateAppointment() method that you call from your main menu, and add the returned appointment object to your list of appointments you'll need to make that function and that list
divolo
divolo12mo ago
namespace appointment_scheduler
{
internal class Appointment
{
public string? title;
public string? date;
public string? time;
public string? location;

public string? Title { get; set; }
public string? Date { get; set; }
public string? Time { get; set; }
public string? Location { get; set; }


}


class program
{

static void Main(string[] args)
{
Appointment appointment = new Appointment();
bool showMenu = true;
while (showMenu)
{
showMenu = Mainmenu();

public Appointment? CreateAppointment();

}

}

private static bool Mainmenu()
{
Console.Clear();
Console.WriteLine("menu");
Console.WriteLine("1 )schedule appointment");
Console.WriteLine("2 )view appointment");
Console.WriteLine("3 )update appointment");
Console.WriteLine("4 )delete appointment");
Console.WriteLine("5 )exit");
Console.Write("\r\nselect an option:");
switch (Console.ReadLine())
{
case "1":

return true;
case "2":

return true;
case "3":

return true;
case "4":

return true;
case "5":

return false;
default:
return true;
}
}
List<Appointment> numbers = new List<Appointment>();


}

the public Appointment CreateAppointment() keeps saying it must be declared
namespace appointment_scheduler
{
internal class Appointment
{
public string? title;
public string? date;
public string? time;
public string? location;

public string? Title { get; set; }
public string? Date { get; set; }
public string? Time { get; set; }
public string? Location { get; set; }


}


class program
{

static void Main(string[] args)
{
Appointment appointment = new Appointment();
bool showMenu = true;
while (showMenu)
{
showMenu = Mainmenu();

public Appointment? CreateAppointment();

}

}

private static bool Mainmenu()
{
Console.Clear();
Console.WriteLine("menu");
Console.WriteLine("1 )schedule appointment");
Console.WriteLine("2 )view appointment");
Console.WriteLine("3 )update appointment");
Console.WriteLine("4 )delete appointment");
Console.WriteLine("5 )exit");
Console.Write("\r\nselect an option:");
switch (Console.ReadLine())
{
case "1":

return true;
case "2":

return true;
case "3":

return true;
case "4":

return true;
case "5":

return false;
default:
return true;
}
}
List<Appointment> numbers = new List<Appointment>();


}

the public Appointment CreateAppointment() keeps saying it must be declared
SinFluxx
SinFluxx12mo ago
well public Appointment CreateAppointment(); is just a method signature, i.e. just the name of the method and what it will return, you haven't created a body for that method
Pobiega
Pobiega12mo ago
also, don't declare methods inside other methods like that and please: $codegif
divolo
divolo12mo ago
public Appointment CreateAppointment()
{
Appointment appointment = new Appointment();
}
public Appointment CreateAppointment()
{
Appointment appointment = new Appointment();
}
like this?
Pobiega
Pobiega12mo ago
something like that you should add more code in that block thou, to ask for details and fill the object before returning it
divolo
divolo12mo ago
im sorry but can you please tell me the steps i should be taking right now
Pobiega
Pobiega12mo ago
well, it seems to me like you already know how to read and write from/to the console so how about you do that?
Accord
Accord12mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ ✅ (SOLVED) TcpListener.AcceptTcpClientAsync does not get cancelled```csharp CancellationTokenSource cancel = new(400); TcpClient JoinedClient = await Server.AcceptTc✅ Tracking changes on a complex object provided by a third party libraryHi! I have a third party .Net Framework dll that allows me to load a file. This file is potentially ❔ ✅ How I can fix download and unzipI wrote a code to download the archive and unpack it but it just creates empty files instead of deco❔ Error message: Cannot convert query to sqlhi i have this code, on line 119 is whats causing the error saying the query cannot be converted to Make a method acessable by scripts extending it, but not by outside scriptsI have private which limits a method to itself, and I have public which lets anything access the metOk so i DID NOT add hello world to my code but it still appearsmy code for some ungodly reason has decided to not use my code and use a previous code when i run an❔ Problem with Quick SortIt seems that it partially sorts it and doesn't finish. I really can't see what is wrong ``` void Qu"name space 'helloworld2' already contains a definition for a 'program'Man this my first code ever in c# it worked two seconds ago and now it dont what do i do pls heres t❔ Windows forms C#Issue with forms resizing when maximizing the window, how do i get rid if the empty space?graphUser almost fully NULL - Graph APIWhen I'm reading the profile and wanting to collect all of it's outlook contacts it's says NULL even