|
All your objects are of type CustomObject, aren't they? (either directly or by inheritance)
If you can Sort the Array, why wouldn't you be able to BinarySearch it?
|
|
|
|
|
Hmm, seems you didn't read my post very carefully , I have an array of CustomObject objects, CustomObject has a property named ID which is an int, I want to search the array for a custom object with that ID or in other words I want to be able to know whether there's a CustomObject in the array with that ID, I'm not interested in returning the object, I just want to know whether it's in the array or not.
Regards
|
|
|
|
|
Array.BinarySearch will look for an element with a specific Property, provided your
IComparer is based on that same Property, hence the Array must be Sorted accordingly.
And it will return a positive index when found, or a negative number when not found.
|
|
|
|
|
I only have the value of the ID property (have a look on the code), I don't have the object, can I pass objects of different types to IComparer.Compare()?
|
|
|
|
|
Hi,
if your IComparer only looks at the object's ID, you could pass it a dummy object with the
ID value you are looking for.
|
|
|
|
|
Hmm, so this means to create an object and assign it the value I want for the ID just for the sake of passing to the IComparer, is my understanding correct? So, as far as I can see, comparing objects of different types is not directly supported by the framework, is this correct?
|
|
|
|
|
Waleed Eissa wrote: to create an object and assign it the value I want for the ID
that was the idea yes
Waleed Eissa wrote: comparing objects of different types is not directly supported
objects of different types are different by definition, no need to compare them.
this is not related to any framework, they differ by definition in OO. chairs aren't tables.
If your different types have a useful common ancestor (say furniture) you should
use that as the basis for your logic.
|
|
|
|
|
How do you divide an image? Say i have a 64x64 pixel image and i want to divide this into two equal and separate triangles (triangle1 U triange2 = original image). I was thinking of using points to create regions. Since the image has four corners that i can use as four starting points, i can choose three of them to "bound" a region. Is this possible? If so could someone provide some sample code?
|
|
|
|
|
No bitmap is ever a triangle. Do you want to create bitmaps that each contain a triangle ?
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
|
Your only other option is a byte array that cannot be displayed until you put it in a bitmap. All bitmaps are square. That's why I'm trying to clarify what you need here.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
So then if i want to create a bitmap that contains a triangle, would I create a bitmap that can enclose the triangle and fill the rest with something like null pixel value?
|
|
|
|
|
No such thing as null, you'd need to choose a color to fill the rest with.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
From what i see in System.Drawing.Region, correct me if Im wrong, I can create a region of any size and shape. System.Drawing.Rectangle uses four points to specify the size of the rectangle using four points, but i dont suppose its possible with System.Drawing.Region using three points? Im not sure if im making sense.
From reading previous posts, i implied that i needed to save these two triangles separately, which meant that i need to display the divided image. However, this is not the case. I just need to divide up an image, perform some changes within those triangles and display them altogether with the changes that were made.
|
|
|
|
|
You can create a region, but that's not a bitmap. I thought a region specified an area on a bitmap, not an irregular bitmap itself.
Yes, I believe the graphics object has a number of methods that take a region and only operate within that region on the bitmap. What sort of changes ?
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Just changing the value of the pixels. Nothing complex. So to create a region using System.Drawing.Graphics, i just use a Point array?
Thanks for the responses.
|
|
|
|
|
yeah, I believe so.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
|
Ok few more questions:
1) How is the coordinate plane set up? Like where would the origin be?
2) could a point be outside of an image?
|
|
|
|
|
Hey:
I have understood the following problem...that u want to convert a rectangular image into two triangles...
"first thing no bitmap is in the form of triangle...Because(by definition) a Bitmap is a rectangular array of pixels...so it can never be triangle"
However u can read the image using byte array...with the help of Marshal.copy method....then copy Half of the array to 1st image array & half to the 2nd image array....
again use.Marshal.copy()method) to convert the bytes array to Bitmap image....
For all the above u must have concept of the following:
1-BitmapData
2-Safe & Usafe code
3-Marshal.copy()method.
Th nks
"Programming is a fun"
|
|
|
|
|
Rao Rafique wrote: However u can read the image using byte array...with the help of Marshal.copy method....then copy Half of the array to 1st image array & half to the 2nd image array....
Not a triangle, you couldn't. Not unless you copied one row at a time. And I explained that in depth, you can have the bytes in memory, but not in a format you can view.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Hello,
lam using the next method of the random class to return integer between 0 and 15 but it repeats some numbers.
so what can I do to prevent it from repeating numbers?
Dad
|
|
|
|
|
you can't, that's what 'random' means.
To do what you want, build a list of 16 ints, 0-15. Get a random number from 0-15 and pull that index out of the array. For your next number, get a random digit between 0 and 14. And so on.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Christian Graus wrote: To do what you want, build a list of 16 ints, 0-15. Get a random number from 0-15 and pull that index out of the array. For your next number, get a random digit between 0 and 14. And so on.
That wouldn't help much because even if you reduce the number each time, you can still get the same number multiple times (if the first Next() returns 3, nothing stops the next call of the method to return 3 again).
You should save the numbers in a generic List, because it has a variable amount of items and you can still access the items by int indexes.
Then call Next() and after getting the value from the list, remove the index that just has been generated by Next (you need to save its result in some variable).
For the next step, you'd need to create a new random with the changed count of the now smaller List as seed (why can't you change the seed of a random after it's been created anyway?).
|
|
|
|
|
Hi all.
How can i hide the mail address of the "sender" of a mail in C#?
Thanks.
|
|
|
|