|
|
I've got 32 arraylists, each representing one team. I also will have 1696 players, with 53 players assigned to each team. Each player is one array (named by player number) that contains that player's attributes (first name, last name, speed, position, etc). I'm having trouble pointing my main menu to a method that will go through all of these players and send players of particular positions to particular methods to obtain their overall rating. Like, for example, if the player is a CB, that player will be sent to the CBCalculator, obtain his overall rating, input it into the player's array, and then loop to the next player in the list. Also, I'm having trouble setting a rating cap--the maximum attainable overall rating will be 99; anything overall rating that is calculated to be above 99 will be set at 99.
This is what I have so far for the position "sorter":
foreach (Player i in teams)
{
switch (position)
{
case "CB":
CBCalc(int SPD);
break;
case "FS":
FSCalc();
break;
default:
Console.WriteLine("Error 2");
break;
}
This is what I have so far for a test Calculator method:
public static void CBCalc(int SPD)
{
double cbOverall = 28 + ((SPD - 50) / 2.5)
int cbOverall2 = Convert.ToInt32(cbOverall);
if (cbOverall2 >= 99)
{
cbOverall2 == 99;
}
http://i783.photobucket.com/albums/yy112/rooster2154/ProgramLayout_10-29-09.jpg
The above link is to help clarify what i'm trying to do and how the program is set up
If you think you can help me along in my project please add me:
YIM: rooster2154
|
|
|
|
|
Hi,
first some comments on your current code:
1. you have "Player" as a type although your description said a player was an array.
2. the foreach loop won't compile as teams does not contain players, it contains zero or more teams.
3. the first line "CBCalc(int SPD);" won't compile as you don't specify type when calling a method, and SPD is unknown.
I do not particularly like your data organization; the structure is OK, the types are not:
1. each player should be an object, an instance of class Player, and not an array. Inside class Player, you could store whatever data you want to keep for players (first name, last name, day of birth, ...), each using the proper type.
2. assuming each player belongs to a single team, each team should be a List<Player> which is slightly easier to use than an ArrayList. I would be inclined to have a Team class that inherits from List<Player>
3. and then you could have a List<Team> to hold your teams.
So the fundamental organization remains the same, the collections used are different (no arrays and no ArrayLists).
Now to iterate over all players, the code would be:
foreach (Team team in teams) {
foreach (Player player in team) {
... whatever
}
}
public class Player {
string lastName;
DateTime DOB;
...
}
public class Team : List<Player> {
... you don't need much code in here, as you can use all the methods inherited from List,
... e.g. you can do Team.Add(new Player());
}
Hope this helps. If you're unfamiliar with any of this, try reading a book on C#, then come back with specific questions.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
How do I read from a text document while along the way putting selected objects from each line into a particular array? and how would i go about creating a counter so that for each line, the counter is increased by 1 and it automatically creates a new list for that line? (I created a Player class.) Also, how would i tell the it to disregard certain lines that have certain symbols at the beginning?
For example:
* Team 1
* firstName LastName position speed etc...
john jackson CB 88
jack robinson QB 55
* Team 2
* firstName LastName position speed etc...
jim johnson FS 92
etc.
in the first line of text the code will read (disregarding the lines marked with asterisks), "john" will be put in a player's firstName, "Jackson" would be put in that same player's lastName variable, same with position, speed, etc.
i already have some of the code i think i will use ( at http://www.csharp411.com/c-read-text-file-line-by-line/[^] )
|
|
|
|
|
Hi,
1.
you need more structure in your file, how about:
; comments start with this special character (choose one)
; whereas keywords start with another special character (choose one)
; $TEAM is a keyword, it is followed by the team name
$TEAM red
; players are listed: firstName; lastName; ...
Jan;Van den Broeck; CB; 88
Gill;Bates; ZZ; 00
$TEAM blue
...
; end-of-file marker
EOF
FWIW: others will recommend other syntax, maybe an XML file; I tend to keep things simple here.
2.
define Player and Team class as I told before; then use List<T> where T is Player/Team (ArrayList is outdated, arrays are no good, you don't know the dimension).
3.
for small files, you can get all lines at once into memory using File.ReadAllLines()
4.
use foreach to iterate over the lines, then test first char for ; and $
5.
make sure you have a "current team", to which the "current player" gets added.
BTW: I strongly advice you buy and study a book on C#.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I'm working on an application that is supposed to take picture from 6 different web cams. I found some code that can be used to take pictures from one web cam, but i was wondering what the i have to do to select
the camera i need.
Any help would be apreciated.
Thanks
|
|
|
|
|
I am sure there are examples here on CP that illustrate listing available input devices and selecting which one to work with
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hey there everyone,
I'm working on a program that gets information from websites. However, there are a few things I'm not really sure how to do.
Basically, I need to go to a page, select a specific radio button, and then hit a button to submit the information. Is there a good way to do this in C#?
Thanks in advance!
*insert sig here*
|
|
|
|
|
C# isn't going to do much, you're going to have to focus on the interfaces offered by the web browser control.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I don't know how C# does web communication, but a submit button just submits (usually POST or GET, but you may have to look for AJAX calls).
Can't you view the source and see what form it is part of, then create your own web call to submit it from your application? That way the response goes directly back to your app.
Or are you trying to make the web browser submit and then display results?
From your question I gathered you want to get the information yourself, but perhaps you are just trying to automate the browser.
Narf.
|
|
|
|
|
how can i show two language text like farsi and english in a textbox together with no commix?
|
|
|
|
|
Just concat them.... I think there shouldnt be any problem using UTF8 charset... (which is supported in string objects)
|
|
|
|
|
hi plz frnds i like to know can be image or video file header so tat we can edit it???
actually i my requirement is to open the header of any file so tat i can edit it.....
|
|
|
|
|
You'll need to find a library that supports editing the file formats you wish to use. I don't know of any and the .NET Framework doesn't come with such a class.
|
|
|
|
|
what do you mean by header???
It is not clear to me.
|
|
|
|
|
Image and video files do have a header in the file format which denotes the format of the file, etc. Changing it without changing the file will probably break his files.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
header is one which contains the information abt the type of file coding n other parameter related to the file ....
|
|
|
|
|
How would changing this help you, if you change it so it's not right for the file in question ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
for my present problem statement i should be able to change it n restore it back...
yup changing it wil effect the file n sometime file may not open also
|
|
|
|
|
They both appear to do the same thing, except Object.Equals documentation says that it throws a NullReferenceException . I can't get it to do that though.
They both test for equality of instances, they both take the same parameters, and they are both static members of System.Object .
I am implementing equality comparison using the standard overrides and operator overloads. I am frustrated with these little details that seem unnecessary.
Documentation says:
Object.ReferenceEquals Method
Determines whether the specified Object instances are the same instance.
Object.Equals Method
Determines whether two Object instances are equal.
EDIT:
I figured it out, I stepped through the code and learned that the static Object.Equals(object a, object b) called in the operator overload actually makes a call to the virtual instance-level Equals(object obj) , so the static ReferenceEquals has to be used to test for instance equality. Though by default the static Object.Equals(object a, object b) will do the same thing as the static ReferenceEquals , unless you override the instance-level Equals method, because by default, the instance-level equals tests for instance equality.
public class Foo : IEquatable<Foo>
{
public static bool operator !=(Foo foo1, Foo foo2)
{
return !Equals(foo1, foo2);
}
public static bool operator ==(Foo foo1, Foo foo2)
{
return Equals(foo1, foo2);
}
public bool Equals(Foo foo)
{
if (foo == null) return false;
return y == foo.y && x == foo.x;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj)) return true;
return Equals(obj as Foo);
}
public override int GetHashCode()
{
return y + 29*x;
}
private int y;
private int x;
}
modified on Thursday, October 29, 2009 2:48 PM
|
|
|
|
|
The answer is simpler than you think... Here's an example:
public class MyClass
{
public string Value { get; set; }
public override bool Equals(object obj)
{
MyClass other = obj as MyClass;
return (other != null && other.Value == Value);
}
}
MyClass a = new MyClass() { Value = "Test" };
MyClass b = new MyClass() { Value = "Test" };
Now... These are two entirely different objects, that happen to contain the same contents. In this case, Equals() returns true, but ReferenceEquals() returns false.
The basic concept is that Equals() indicates logical equivalence... Dunno if that's the right term... It tests whether the two objects are equivalent in terms of what they contain (At least, it's supposed to - You're supposed to override it in classes you create). ReferenceEquals() always tests whether two references point to the same physical object in memory.
EDIT:
CaptainSeeSharp wrote: if (ReferenceEquals(this, obj)) return true; //why use Object.ReferenceEquals here and not Object.Equals(obja, objb)?
//They do the same exact thing as far as I can tell
To add... That's a shortcut. ReferenceEquals() is a much faster operation, since you're just testing whether two pointers are equal. Obviously if the two references point to the same object, testing Equals() (Which may have a lengthy implementation, such as comparing every element in an array) is superfluous.
|
|
|
|
|
Just beat me to it!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Didn't quite answer my question, but thanks anyways.
|
|
|
|
|
Object.Equals tests for Equality i.e. the two objects have the same values. Take a look at the example code on the MSDN Page for a demo.
Object.ReferenceEquals tests if they are in fact the same object i.e. it is the same pointer.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I figured it out, I stepped through the code and learned that the static Object.Equals(object a, object b) called in the operator overload actually makes a call to the virtual instance-level Equals(object obj) , so the static ReferenceEquals has to be used to test for instance equality. Though by default the static Object.Equals(object a, object b) will do the same thing as the static ReferenceEquals , unless you override the instance-level Equals method, because the default instance-level Equals method tests for instance equality.
modified on Thursday, October 29, 2009 2:48 PM
|
|
|
|