You can read either in LINQ or ArrayList, in your case I prefer to read in ArrayList.
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
Make a struct from your data :
struct Employee
{
string name;
public int age;
public bool ID;
private int salary;
}
Now make an ArrayList of Employee as RamyMahrous pointed out.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
We will give you bricks, wood, mortar, any other materials if needed.
We will not build your house.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Give us hint you tried, if you declare instance from ArrayList class and pressed '.' you'll find someone much greater than us with all respect to my friend Ddanbe. it's intellisense and documentation.
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
have a look in the helpfile as to try, and then show us your code, and the errors and/or explain in what way it hadnt done what you wanted..
Then we will help
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
What's this??
You need to read in Structures as well.
Let us start.
1- I need you do initialize an array of 5 elements from human datatype
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
No, it sorted the numbers as you told it to - or at least it did when I ran it.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
namespace ConsoleApplication54
Seems to me you have tried already something out!
But you look like a blind man who is trying to break an egg with a stick!
So first things first : forget for a moment your end result.
Concentrate on making a struct :
struct human
{
string name;
int age;
bool ID;
int salary;
}
Make a program with only the struct. Does it compile? Does it run?
Find out what a struct is Google, MSDN, books you have, Help menu.
If you done all that try to go a step further, if you are stuck come back.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
i want to it show me the max and min salary and the sort number after i gave it to program not the character are in the this line
string[] cArray = new string[3] { "Cha3123", "Cha1234", "Cha1243" };
Well your code only dumps out the values in the array, if you wish for min and max then you would have to add the code for that.. But
It printed them out in numerical order for me when I ran your code
Which is exactly what you told it to.
If you wish it to do so *AFTER* you have entered some data, change your code to ask for some data, and store it, and then run the sort.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
well, seems you don't need to try we've absolved responsibility regards this, I'll try it after some minutes and come back with C# code.
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
Here's some codes...
List<Human> Humans = new List<Human>();
void Add(Int16 humanID, string humanName, Int16 humanAge, float humanSalary)
{
Humans.Add(new Human(humanID, humanName, humanAge, humanSalary));
}
float GetMaxSalary()
{
float maxSalary = 0;
foreach (Human aHuman in Humans.ToArray())
{
if (aHuman.SALARY > maxSalary)
maxSalary = aHuman.SALARY;
}
return maxSalary;
}
float GetMinSalary()
{
float minSalary = GetMaxSalary();
foreach (Human aHuman in Humans.ToArray())
{
if (aHuman.SALARY < minSalary)
minSalary = aHuman.SALARY;
}
return minSalary;
}
float GetAverage()
{
float totalSalary = 0;
foreach (Human aHuman in Humans.ToArray())
{
totalSalary += aHuman.SALARY;
}
return totalSalary/Humans.Count;
}
}
struct Human
{
public Int16 ID;
public string NAME;
public Int16 AGE;
public float SALARY;
public Human(Int16 humanID, string humanName, Int16 humanAge, float humanSalary)
{
ID = humanID;
NAME = humanName;
AGE = humanAge;
SALARY = humanSalary;
}
}
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
float minSalary = GetMaxSalary();
You could also do float minSalary = Humans.Max();
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Thank you Danny so much, but he may don't have .NET framework 3.5
I hope he replies he could solve the problem.
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
?! I've did for you almost all functions your program should do. Just try to make use of them and have a deep look inside the code to learn how things done.
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276