|
1 is just a specialization of 2. So solve 2 first.
|
|
|
|
|
Attempted number 2 in the previous message.
Please have a look.
Thanks
|
|
|
|
|
Well, it sure looks like number two...
|
|
|
|
|
|
Please don't remove any more posts. It's antisocial because you don't allow others to see what you are trying to accomplish.
|
|
|
|
|
Clue Line announcement: this station not serviced on Saturdays.
|
|
|
|
|
Luc Pattyn wrote: this station not serviced on Saturdays
That's a pity, I was going to suggest that the first one is really easy:
arkiboys wrote: 1-
private int CalculateBiggestValue(int[] anyOldOrderValues);
Question:
CalculateBiggestValue should return the single highest integer
private int CalculateBiggestValue (int[] anyOldOrderValues)
{
return int.MaxValue;
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
|
Hi
How is it possible to add Tag to CheckedListBox.Items
Something like :
CheckedListBox2.Items[0].Tag ="0913273";
Or
CheckedListBox.Items.Add(Text,Tag);
ex:
CheckedListBox2.Items.Add("Ali","0913273");
|
|
|
|
|
Why not try something like this (not compiled, syntax errors are an exercise for the implementer!):
class DataItem
{
public string Text { get; set; }
public string Tag { get; set; }
public override string ToString()
{
return Text;
}
}
Then:
CheckedListBox.Items.Add(new DataItem { Text = "Ali", Tag = "0913279" });
If you want to change the tag, you will also be able to do:
(CheckedListBox2.Items[0] as DataItem).Tag ="0913273";
This assumes that CheckedListBox2.Items[0] is a DataItem , otherwise you'll get a NullReferenceException .
You can then retrieve the item, and get the text and tag. The ToString() function is used to determine what label should be given to the item.
Note: Just reeled off of the top of my head. Untested, but I think it should work. Also assuming you're working with VS2008 or later.
Edit: It is a good idea to wrap code in <pre> or <code> tags to make them easier to read (as in my code samples).
|
|
|
|
|
I have a burning question about interfaces. When I have a class that implements an interface, and I create the interface with the class like so:
Interface iSomething;
Class ImplementsISomething : iSomething
{
}
iSomething Something = new ImplementsISomething();
And then I pass the interface to another class like so:
class AnotherClass
{
iSomething refedSomething;
public AnotherClass(ref iSomething passedInterface)
{
refedSomething = passedInterface;
}
}
AnotherClass aClass = new AnotherClass(ref Something);
Now, when I pass the interface, does the interface act as a pointer to my base class, or every time I pass an interface to a class that uses it does that class take up the same amount of memory as creating another instance of the class would? This is mainly a question of does the interface take up the same amount of memory as an instance of the class, or is it just an address?
|
|
|
|
|
The interface has no effect on the size of the class/reference.
|
|
|
|
|
you can't instantiate an interface. When you "pass an interface" as you call it, you actually pass an object, more in particular an instance of some class that implements said interface. Therefore its size depends on the class, not the interface. An interface is a contract, a promise that the class will implement a list of methods and/or properties.
|
|
|
|
|
I had to read your question twice to understand it. The answers to your questions are (in the order):
1. Yes, it is just a pointer
2. No, an interface only points to something, it always takes the same amount of memory and
3.1 No it does not take the same amount of memory as the class (which implements it) and
3.2 No, it is just an address
...to express it in your words. An interface is a reference type, meaning that it always only points to something which 'implements it'. That might be a value or reference type but that does not matter. I heartily recommend to read on a bit about basics of C#, since you seem to have missed some very central points.
btw, you should also re-read on the meaning of ref , I am quite sure that you misinterpreted that too...
modified on Sunday, September 12, 2010 6:47 AM
|
|
|
|
|
Yeah I got tired of waiting for an actual answer on here so I just did some tests and found the answer. It is just a pointer. And I get ref, I am well aware of what happens when you pass by reference and by value. And I am well aware of the central points of C#, just do C++ at my studio for our engine. 9 Hours a day of C++ and then going home to do C# is a kind of rough transition. I just equate things to C++ which is my naitive language. I did a GC memory check at the begining and end of creation of the class in question and just watched how many bytes were used with two different versions of the class. I applaud you though, your the first one to actually get the question right. Wait, correction, I think the first response got the question right too.
modified on Sunday, September 12, 2010 4:44 PM
|
|
|
|
|
Actually, you got the correct answer from all three. You should reread what Luc had to say on the subject as well, as you've not read it through properly; he's one smart cookie and he provided the info from the other side.
|
|
|
|
|
I guess I got kind of confused when Luc said that it depends on the size of the class. I took it to mean that he was saying that when declaired as an interface and passed as an interface type it still got passed as a class. So I dont think I got the right answer from all three, because two of the answers were the same and one said the opposite. But you guys have all been very helpful and I appreciate it. Especially paul_71, your answer was very precise and had the information I was looking for to begin with. But like I said, did some research on my own and found my answer like I should have in the first place.
|
|
|
|
|
As a side note, I would like to thank you all for your help. I hope I did not come of as mean.The transition from C++ to C# is a frustrating one to say the least. The managed environment is exciting and taxing at the same time. I appreciate you all for taking the time to answer my question.
|
|
|
|
|
You are welcome... I saw that Luc's answer already contained the required information, but I decided to give a more 'explicit' version for a specific reason: I saw that you're coming from C++. It is really interesting that the way experienced C++ devs are approaching the CLI (esp. C#) world is the same all over the world
|
|
|
|
|
I just want pointers! I looked into using them with the unsafe environement, but it is way to unstable! Just give me pointers!
|
|
|
|
|
Assuming I have a string of numbers beginning with "6" (i.e., "612345"). I wish to check if the numbers 6, 2, and 4 appear in that order. Thus, I can check for "6[0-9]*2[0-9]*4" using regular expressions. However, knowing that the numbers I'm checking have to begin with a 6, does it actually save me time to only search for "2[0-9]*4"? The reason I ask is because logically, using the first search, "6" would be found in the first character and "2" would start from the second character. However, using the second search, "2" would start from the first character which I already know to be a "6". In the first case, I get code readability, while in the second, I'm only searching for what the minimum is needed. I'm wondering if there is any optimization technique that could possibly make the first method run faster than the second?
Thanks!
|
|
|
|
|
some comments, not an answer:
1.
we have a regular expressions forum
2.
you're worried about readability and yet you use regular expressions?
3.
what do you want to happen with numbers having multiple two's and four's?
is 612423 two matches? a match and a fail?
|
|
|
|
|
Luc Pattyn wrote: 1.
we have a regular expressions forum
I knew I should have checked all the forums. However, I am using C#. Maybe someone will move this to the right forum.
Luc Pattyn wrote: 2.
you're worried about readability and yet you use regular expressions?
It's a simple numeric search. I could easily add a comment that I'm actually searching for 6-2-4, but only 2-4 is needed since the numbers begin with 6.
Luc Pattyn wrote: 3.
what do you want to happen with numbers having multiple two's and four's?
is 612423 two matches? a match and a fail?
As long as there's a 2 before a 4, it passes. The string 612345 was just an example. It could be 64444444444444422222222222123678901236789012345678903456789034567890 and it would still pass.
|
|
|
|
|
Bassam Abdul-Baki wrote: as there's a 2 before a 4, it passes
Check for the 6
Compare String.IndexOf ( 2 ) < String.LastIndexOf ( 4 ) (Check for -1 too)
Done
|
|
|
|
|
Nice! I like this, but my example only had two numbers for simplicity. I actually have three numbers. Missed it by this much.
|
|
|
|