M
Mikkyever
Guest
I want to loop through the content in the static list but its output is the namespace.
Here is what I got:
Welcome to ToDoList App
Would you like to add an item to your list or View Your List? (Add/View)
Add
Enter your Item:
Make Tea
Your Item has successfully added to the List
Would you Like to Add another Item or View your Items? (Add/View)
View
ToDoList.Models.Item
Any Ideas to how I can achieve my desired output?
Code Below
Program.cs
using System;
using System.Collections.Generic;
using ToDoList.Models;
namespace ToDoList
{
class Program
{
static void Main()
{
Console.WriteLine("Welcome to ToDoList App");
Console.WriteLine("Would you like to add an item to your list or View Your List? (Add/View)");
string inputString = Console.ReadLine();
if(inputString == "Add")
{
Add();
}
else if (inputString == "View")
{
View();
}
else
{
Console.WriteLine("You entered an invalid option");
}
}
static void Add()
{
Console.WriteLine("Enter your Item:");
string inputItem = Console.ReadLine();
Item newItem = new Item(inputItem);
Console.WriteLine("Your Item has successfully added to the List");
Console.WriteLine("Would you Like to Add another Item or View your Items? (Add/View)");
string reply = Console.ReadLine();
if (reply == "Add")
{
Add();
}
else if (reply == "View")
{
View();
}
else
{
Console.WriteLine("You entered an invalid option");
}
}
static void View()
{
List<Item> newList = Item.GetAll();
foreach (Item task in newList)
{
Console.WriteLine(task);
}
}
}
}
Item.cs
using System.Collections.Generic;
using System;
namespace ToDoList.Models
{
public class Item
{
public string Description{get; set;}
private static List<Item> _instances = new List<Item> {};
public Item(string description)
{
Description = description;
_instances.Add(this);
}
public static List<Item> GetAll()
{
return (_instances);
}
public static void ClearAll()
{
_instances.Clear();
}
}
}
Continue reading...
Here is what I got:
Welcome to ToDoList App
Would you like to add an item to your list or View Your List? (Add/View)
Add
Enter your Item:
Make Tea
Your Item has successfully added to the List
Would you Like to Add another Item or View your Items? (Add/View)
View
ToDoList.Models.Item
Any Ideas to how I can achieve my desired output?
Code Below
Program.cs
using System;
using System.Collections.Generic;
using ToDoList.Models;
namespace ToDoList
{
class Program
{
static void Main()
{
Console.WriteLine("Welcome to ToDoList App");
Console.WriteLine("Would you like to add an item to your list or View Your List? (Add/View)");
string inputString = Console.ReadLine();
if(inputString == "Add")
{
Add();
}
else if (inputString == "View")
{
View();
}
else
{
Console.WriteLine("You entered an invalid option");
}
}
static void Add()
{
Console.WriteLine("Enter your Item:");
string inputItem = Console.ReadLine();
Item newItem = new Item(inputItem);
Console.WriteLine("Your Item has successfully added to the List");
Console.WriteLine("Would you Like to Add another Item or View your Items? (Add/View)");
string reply = Console.ReadLine();
if (reply == "Add")
{
Add();
}
else if (reply == "View")
{
View();
}
else
{
Console.WriteLine("You entered an invalid option");
}
}
static void View()
{
List<Item> newList = Item.GetAll();
foreach (Item task in newList)
{
Console.WriteLine(task);
}
}
}
}
Item.cs
using System.Collections.Generic;
using System;
namespace ToDoList.Models
{
public class Item
{
public string Description{get; set;}
private static List<Item> _instances = new List<Item> {};
public Item(string description)
{
Description = description;
_instances.Add(this);
}
public static List<Item> GetAll()
{
return (_instances);
}
public static void ClearAll()
{
_instances.Clear();
}
}
}
Continue reading...