|
Nope. Not a C# question.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
|
|
arkiboys wrote: Can you please see if you can answer the questions to get the values correctly?
How can anyone do that without seeing your code?
It's time for a new signature.
|
|
|
|
|
CalculateBiggestValue aka Max is not a very hard function to write, what is your code now?
FindTopNValues is not as easy, and the advanced algorithms actually change the order of element in the input array.
Wikipedia has a good article about this: http://en.wikipedia.org/wiki/Selection_algorithm[^]
|
|
|
|
|
|
Almost; but you have no test.
|
|
|
|
|
PIEBALDconsult wrote: Almost
you're in weekend mood I presume.
|
|
|
|
|
|
Obviously this function does not calculate all n top values. The return type doesn't even match the type of the return expression.
At a first glance it seems to correctly calculate the highest value (apart from the loop condition anyway), though I'm not sure why you're casting an int to an int .
|
|
|
|
|
That looks more like a solution to 1.
|
|
|
|
|
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
|
|
|
|