|
Hi
I am converting some code from Java to C#.
RandomAccessFile class is used in Java application. What would be replacement of this class in C#.
Thank You
James
|
|
|
|
|
Just a FileStream, I'd have thought. They have a Seek method, which makes it random access, right ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
Hi,
I have issue converting sbyte[] to byte[] array. My function(actually third party dll) returns sbyte with negative values. My question is how to put this sybte[] info( contains info of image) in to httpResponse object which takes only byte[] array.
Response.Expires = -1;
Response.Buffer = true;
Response.ContentType = "image/gif";
byte[] mapContent=null;
sbyte[] shortContent=mapFormat.DrawMap(map);
Response.BinaryWrite(?????)----- takes only byte[] info..
Thanks...
|
|
|
|
|
Like this:
mapContent = Array.ConvertAll<sbyte, byte>(shortContent, delegate(sbyte s) { return (byte)s; } );
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Thanks.. It solved the issue now... I am doing conversion with 2s compliment. when i do it normally, negative values overflows and returns error message. I am using 1.1 version. Now I am getting maps..
for(int i=0;i< shortContent.GetLength(0);i++)
{
if(i==0)
mapContent=new byte[shortContent.GetLength(0)];
sval=shortContent[i];
if ( sval < 0 )
val = (byte)(256 + sval);
else
val = (byte)sval;
mapContent[i]=val;
}
|
|
|
|
|
Hi,
I'm trying to code a tetris game in a windows form.
I have a class named fallingobject and since in the tetris game there are 4 shapes of fallingobjects, I've created 4 instances of fallingobject class and added them to a array (named as objcts) of type : fallingobject
If for example next shape is square I'm going to need an instance of objcts[0] element and change the coordinates property of it in my functions. But I don't want to change the properties of the object in the array, I only want to change the properties of the instance, but it changes as well, when I write the following code:
<br />
fallingobject fllnobjct;<br />
Random r = new Random();
fllnobjct = objcts[r.Next(4)]; <br />
It's probably because I'm referencing the object in the array and it's my mistake, but when I do the following:
fallingobject fllnobjct;<br />
Random r = new Random();<br />
int rndm = r.Next(4);<br />
fllnobjct= new fallingobject (objcts[rndm].coordinates,objcts[rndm].colour);
it happens to me when I write the code above, I'm creating a new instance with properties of the array element as parameters so the array element shouldn get affected by the changes in the instance but same thing happens again..
how should I define the instance so that it doesn't change its mother class?
|
|
|
|
|
This is an issue with the copy constructor in the fallingobject class. Try making fallingobject a struct, if you can. Otherwise, impliment and use the clone method to make a copy of the object.
fllnobject . objcts[r.Next(4)].Clone();
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
It shouldn't happen when you are creating a new instance and using the existing instance's properties in the constructor call.
Create a constructor in fallingobject that accepts a parameter of type Fallingobject
public fallingobject(fallingobject existingInstance){ }
and in there copy the properties from the old instance to the other.
You should maybe look into the ICloneable interface?
Edit: You did it again Christian!
Dave
|
|
|
|
|
Hi,
the way you go about this seems wrong to me. You have four different kinds of objects,
so there should be four classes, probably all deriving from one common class, say:
class Shape { ... }
class Rect : Shape { ... }
class ZShape : Shape { ... }
class LShape : Shape { ... }
class LongShape : Shape { ... }
Now put common methods in Shape, and specific ones in the specific classes; then
create a new shape whenever you need one by instantiating the right class.
In this way, you never need to copy or clone an existing object.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Im trying to access a listbox control located on my main form inside an AsyncCallback method and getting cross thread errors as AsyncCallback is on a seperate thread. I decided then to create a new delagate and fire an event from within the AsyncCallback method thinking this would solve the problem but that too was executed on a seperate thread.
How can i fire an event from inside the method that runs on the main thread?
thankyou.
|
|
|
|
|
Hi,
as always, GUI components need to be handled by the GUI thread; COntrol.InvokeRequired,
and Control.Invoke() take care of that. There are plenty of examples everywhere.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Yes
exactlly.
use the any control.invoke() for that.
Cheers
RRave
MCTS,MCPD
|
|
|
|
|
I have about 200+ songs in my library but they're only sorted by artist. I want to have it sorted by Artist then by Album. I googled and I can't find anything on how to get special attributes of a file like mp3's. Does anyone know how I would do this is C#?
Thanks.
|
|
|
|
|
There are a number of classes for reading ID3 tag information about on the web. I used one ages ago, in .NET 1.1. It supported id3V1 ( which is trivial, the data is just on the end of the file ) and if3V2 ( which is not, the data is compressed on the end of hte file )
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Check out TagLib#. It probably supports more filetypes than you need, but it was made to do exactly what you're looking for.
|
|
|
|
|
All right thanks man. I'm gonna archive this for future use.
modified on Saturday, February 16, 2008 2:25 PM
|
|
|
|
|
I have the following class:
class Foo<T> where T : EventArgs { } Now I have an object and I want to see if it's a type Foo<?> (that is, a Foo<Anything> ). How do I do this?
bool isAFoo = someObject is Foo<>;
|
|
|
|
|
Hi Judah,
this compiles, and might be what you want:
class Foo<T> where T : EventArgs { }
class test {
private void aha() {
Foo<MouseEventArgs> mea=new Foo<MouseEventArgs>();
bool isFoo=mea is Foo<EventArgs>;
}
}
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
While it compiles, isFoo == false, which isn't what I was looking for.
|
|
|
|
|
Judah Himango wrote: While it compiles, isFoo == false, which isn't what I was looking for
SO there is an improvement, a minor one at that
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
The only way to do that would be to get the type name as a string, and examine it. Two types derived from the same generic type are still two completely different types, there is no grouping of types.
Why do you want to know if the object is derived from a specfic generic type? You still can't use the object for anything based on that information. You have to cast the object to some specific class or interface to be able to do anything with it except what the Object class provides.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Guffa wrote: The only way to do that would be to get the type name as a string, and examine it.
I was able to do a little better. someObj.GetType() == typeof( Foo<> ) actually works.
Guffa wrote: Why do you want to know if the object is derived from a specfic generic type? You still can't use the object for anything based on that information.
Indeed, sounds like we have a design flaw. Thanks for your input.
|
|
|
|
|
|
Swap the parameters, you have them in the wrong order.
client = new Client(sm, sc, txtThread2, btnStart, btnStop);
client = new Client(sc, sm, txtThread2, btnStart, btnStop);
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|