Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,208,269 members, 8,002,110 topics. Date: Thursday, 14 November 2024 at 12:59 AM |
Nairaland Forum / Science/Technology / Programming / Help! Im Stuck With This C# Program (1648 Views)
Please Guys Help Me With This C++ Program Exam Question. It's Urgent. / Fix This C++ Code If You can / Please Programmars Help Me Out With This C# Program! I Have Test Tommorrow!!!!! (2) (3) (4)
Help! Im Stuck With This C# Program by Nobody: 6:21pm On Apr 01, 2016 |
I'm a beginner programmer learning C#I coded two apps, which I named the Contact app and list app. What the first one does is printing out the input that was passed into the parameter. Here"s the code: using System; The second one makes use of C# List to add and remove elements: using System; Now, I tried combining these two programs so that I create a List of Contact with a loop that runs and asks the user to enter a name, a phone number, and add all the info into the list. This is what I came up with but it's not working:
I ended up getting this message from VS Error 1 The best overloaded method match for 'System.Collections.Generic.List<ConsoleApplication4.contact.Contact>.Add(ConsoleApplication4.contact.Contact)' has some invalid arguments c:\users\user\documents\visual studio 2010\Projects\ConsoleApplication4\ConsoleApplication4\Program.cs 49 17 ConsoleApplication4 Error 2 Argument 1: cannot convert from 'string' to 'ConsoleApplication4.contact.Contact' c:\users\user\documents\visual studio 2010\Projects\ConsoleApplication4\ConsoleApplication4\Program.cs 49 31 ConsoleApplication4 Pls what do I do to get things right? I think I've really lost my track. larisoft |
Re: Help! Im Stuck With This C# Program by Nobody: 7:10pm On Apr 01, 2016 |
Why are you converting from string to a public class.... |
Re: Help! Im Stuck With This C# Program by Nobody: 7:25pm On Apr 01, 2016 |
Use List<string> namelist = new List<string>(); add using System.Collections.Generic; |
Re: Help! Im Stuck With This C# Program by larisoft: 7:42pm On Apr 01, 2016 |
Well done, bro. The problem with your code is that you declared your list to accept only contact objects (List<Contact>, but you are trying to force a string object into it (namelist.add(name)). Now, this will work; List<Contact> nameslist = new List<Contact>(); Console.Write("Enter your name" ); string name = Console.ReadLine(); // I've stored it into a string now //we are adding a contact object to a contacts list Contact contact = new Contact(); contact.setFullName(name); nameslist.Add(contact); int i = 0; while(name!="Quit" // I want the program to end if a user enters "Quit". Console.WriteLine(i); i++; ------OR--- //use a simple string list instead of a contact list List<String> nameslist = new List<String>(); Console.Write("Enter your name" ); string name = Console.ReadLine(); // I've stored it into a string now nameslist.Add(name); int i = 0; while(name!="Quit" // I want the program to end if a user enters "Quit". Console.WriteLine(i); i++; } |
Re: Help! Im Stuck With This C# Program by larisoft: 7:45pm On Apr 01, 2016 |
Also note that you should use if(!name.Equals("Quit")) as opposed to (name!="Quit"). Keep it up. |
Re: Help! Im Stuck With This C# Program by mbatuku1: 8:46pm On Apr 01, 2016 |
Thanks larisoft and basbone. I will work on the suggestions and update the house. |
Re: Help! Im Stuck With This C# Program by elfico(m): 4:18pm On Apr 04, 2016 |
mbatuku2:You can use an ArrayList for a dynamic array |
Re: Help! Im Stuck With This C# Program by Nobody: 8:21am On Apr 05, 2016 |
Try to combine the three class together . |
(1) (Reply)
Create A Beautiful Android Weather App Using Openweathermap API / Hi guys review this my app: a whatsapp, 2go, instagram, olx, game app all-in-one / 8 Best Android Apps Maker
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 22 |