TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajesh Thampi
NA
12
526
Generic List | Console printing
Nov 1 2017 3:48 AM
Hi guys
I have a class like following
class
Employees
{
string
empName;
string
deptName;
double
salary;
double
bonus;
public
Employees(
string
eName,
string
dName,
double
eSalary,
double
eBonus)
{
this
.empName = eName;
this
.deptName = dName;
this
.salary = eSalary;
this
.bonus = eBonus;
}
}
and in my main method I am trying to create a List using the class like following:
class
TestGenericList
{
static
void
Main()
{
List
myList =
new
List
();
Employees rajesh =
new
Employees(
"Rajesh Thampi"
,
"IT"
, 1125.000, 300.000);
myList.Add(rajesh);
foreach
(Employees obj
in
myList)
{
Console.WriteLine(obj);
}
}
}
How do you I print each element from the list object at the console?
I want to print the output like this
Console.WriteLine("Employee Name: {0}, Department: {1}, Salary: {2}, Bonus: {3}", ?, ?, ?, ?);
I am totally outta clue here. Please help :)
Reply
Answers (
3
)
Program Issues and Seeking Help
Both DataSource and DataSourceID are defined on 'MedicalSche