|
|
I'm trying to find the straight forward way to sort a single array of dates.
string[] datearray = new string[10]
here is a sample...
i want this:
12/27/2005
12/28/2005
01/01/2006
01/02/2006
01/04/2006
01/05/2006
12/29/2005
12/30/2005
12/31/2005
01/03/2006
to look at this:
12/27/2005
12/28/2005
12/29/2005
12/30/2005
12/31/2005
01/01/2006
01/02/2006
01/03/2006
01/04/2006
01/05/2006
any clues?
|
|
|
|
|
Why are you storing them as strings instead of DateTimes?
Jon Sagara
Look at him. He runs like a Welshman. Doesn't he run like a Welshman? Doesn't he? I think he runs like a Welshman.
Sagara.org | Blog | My Articles
|
|
|
|
|
thats all you needed to say... i fixed it. I needed the output in string format so i had a brain fart and started converting it early... thanks
|
|
|
|
|
I'm looking to access some file properties such as the Author and comments. Where is this information stored? Is there a .Net class that allows access?
|
|
|
|
|
Have you tried hte FileInfo Class?
|
|
|
|
|
I have but it does not expose the information that I'm looking for.
For example if you right click a file choose properties then choose the summary tab. The information that might be present here is what I'm after.
|
|
|
|
|
In that case you'll probably have to pinvoke a win32 api call to do this. You might want to try asking in the c++ forum since win32 is provided as c++ style dlls and 'documented' as .h files.
|
|
|
|
|
Simple question--one would think (...but I'm pulling my hair out).
I'm trying to drag a control (say a button) in a Windows app at runtime.
The button, as I drag it, appears to split into two button images (with each
"instance" having its location updated about half the time.)
My code, in the Form1 class:
-----------------------------------------------------
bool isDragging = false;
Point anchor;
private void button1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDragging = true;
anchor = new Point(e.X,e.Y);
}
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && isDragging)
{
button1.Location += new Size(e.X-anchor.X, e.Y-anchor.Y);
anchor = new Point(e.X,e.Y);
}
}
-----------------------------------------------------
Please save my hair!!
THANKS,
Tom
|
|
|
|
|
|
If i want to store a value in the registry,somthing like:
[Intalation path]+"\\HelpFiles\\Help.htm"
How would i get the inatalation so i can enter it into the setup project registry editor?
Thanks.
|
|
|
|
|
I have an application that retrieves data from a socket. The process is periodically not returning any results. I have tried the following methods for connecting to the socket in an attempt to resolve the issue but have been unsuccessful. Is this a problem in my code or is it related to network issues? What can be done to better track this issue and resolved it?
Code Option #1
<br />
Dim Client As System.Net.Sockets.TcpClient<br />
Dim netStream As NetworkStream<br />
''
Client = New System.Net.Sockets.TcpClient<br />
Client.NoDelay = False<br />
Client.Connect(Switch.IPAddress, Switch.Port)<br />
netStream = Client.GetStream()<br />
''
Do<br />
numberOfBytesRead = netStream.Read(bytes, 0, uCVT.IntNulls(Client.ReceiveBufferSize))<br />
Loop While netStream.DataAvailable<br />
''
If Not netStream Is Nothing Then netStream.Close()<br />
If Not Client Is Nothing Then Client.Close()
Code Option #2
<br />
Dim Socket As Socket<br />
''
Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)<br />
Dim rEP As New IPEndPoint(IPAddress.Parse(Switch.IPAddress), Switch.Port)<br />
Socket.Connect(rEP)<br />
''
Dim bytes(1024) As Byte<br />
Dim bytesRec As Integer = Socket.Receive(bytes, 0, Socket.Available, Net.Sockets.SocketFlags.None)<br />
''
If Not Socket Is Nothing Then Socket.Close()
Thank you,
Jason W.
|
|
|
|
|
I'm confused on the following:
public class mydef
{
int int1;
int int2;
...
pubic void SetValues(int f, int s)
{...}
}
mydef myobj;
myobj.SetValues(1,2);
mydef myobj2;
myobj2 = myobj; // CAN I DO THIS?
myobj.SetValues(3,4);
... What have I just done?
Is it as straight forward as it seems? Did I simply set the values in myobj, create a new object and set it's values to those in myobj, and then modify the values in myobj without affecting myobj2?
If not, how would I do this?
|
|
|
|
|
You set the myObj2 variable to reference the value pointed to by myobj variable. Is that what you intended to do?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Morality Apart from God
Judah Himango
|
|
|
|
|
No, that is not what I intended to do.
What I would like to do, is to copy all the fields from myobj into myobj2 without setting them to the same object reference.
|
|
|
|
|
Because mydef is a class, all your variables (myobj, myobj2 ) are references to the same object.
budidharma wrote: myobj2 = myobj; // CAN I DO THIS?
You can do that, but now myobj2 and myobj both point to the same object. So
myobj.SetValues(3,4); is the same as myobj2.SetValues(3,4);
If mydef was a struct, and you did myobj2 = myobj; ,
myobj2 was a different object than myobj (someone pleas correct me if i'm wrong). myobj is then sort of copied to myobj2 .
Hope this makes sense
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
That's what I was afraid of. I don't want to set myobj2 to the location in memory of myobj. I want to copy all the data from myobj into myobj2.
I don't want this to be written as structs.
I know I could simply write a copy function:
public static void Copy(mydef myobj, mydef myobj2)
{
myobj2.Set(myobj.Get())
}
But that's a very long winded and very ... not elegant.
What's the better method of doing this in C#?
|
|
|
|
|
The usual/recommended way is to implement IClonable.Clone . What i usually do is something like this:
public class MyDef : IClonable {
...
protected MyDef(MyDef original){
}
public object Clone {
return new MyDef(this)
}
public static MyDef Copy(MyDef original){
return new MyDef(original)
}
...
}
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
-- modified at 12:28 Tuesday 1st November, 2005
|
|
|
|
|
Thank you. Above what you wrote is how I was thinking about doing it.
But now that you've mentioned the ICloneable interface, I'd like to learn that method as well.
I've been searching for a tutorial on this for over an hour, and have not found one. I'm not exactly how to use it.
Can you explain a little bit about this? Thanks.
|
|
|
|
|
|
Awesome, thank you very much.
I also noticed that there is an IComparable interface.
Am I correct in assuming that IComparable is implemented just like ICloneable, with the appropriote changes?
And is it preferable to implement IComparable rather than overloading the == operator?
|
|
|
|
|
You're welcome
You can also implement IComparable is you want, but that interface is normally used for sorting and stuff (according to MSDN[^], the Remarks section). To be honest, i never used IComparable, because i never sorted anything...
So if you don't want to sort, but just want to have a way of telling if the two instances are equal, I would override Equals(obj) . There's also a static overload of Equals, but you don't have to override that, because it just calls the Equals of the first object. And if you want, you can overload/overidde the == operator, and then just call Equals:
public override bool Equals(object obj){
}
public operator ==(object obj){
return this.Equals(obj)
} For more info about Equals, IComparable and sucj, you can read this article: General Guidelines for C# Class Implementation[^]
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
God, I must be really annoying by now ... but I'm having some problem i can't seem to find. I'm sure I'm overlooking something stupid.
... relevant methods from the card class ...
<br />
public Card(Card c)<br />
{<br />
m_Rank = c.GetRank();<br />
m_Suit = c.GetSuit();<br />
}<br />
<br />
public object Clone()<br />
{<br />
return new Card(this);<br />
}<br />
... relevant methods from the deck class ...
<br />
public void Shuffle()<br />
{<br />
Random rand = new Random();<br />
<br />
for (int i = 0; i < 52; i++)<br />
{<br />
int first = rand.Next(52);<br />
int second = rand.Next(52);<br />
<br />
Card tempCard = m_Deck[first].Clone();<br />
m_Deck[first] = m_Deck[second].Clone();<br />
m_Deck[second] = tempCard.Clone();<br />
}<br />
<br />
}<br />
... Throws the error:
Error 4 Cannot implicitly convert type 'object' to 'Poker.Card'. An explicit conversion exists (are you missing a cast?) C:\...\Cards.cs 246 33 Poker
I tried to fix it myself, can't seem to figure out where the problem is.
When I call clone, it creates a new object from this and returns it cast as a card. I thought I'd be able to simply set an object equal to that new object ... apparently not though.
I also tried:
Card c = new mycard.Clone(); ... that throws an error as well.
Sorry for so many questions. Thank you for all the help.
|
|
|
|
|
God, I just figured out what you meant. You said with this method, I need to manually cast each return value, for example:
Card tempCard = (Card)m_Deck[first].Clone();
Apparently it's because Clone returns an object. Screw that! I'm going to use the latter static method that returns a Card!
Thanks again for all the help.
|
|
|
|
|
You're not annoying at all, i'm happy to help!
I'm glad you figured it out yourself. Of course, i can explain (almost) everything for you, but a real programmer can solve problems, i think.
But that doesn't mean you should stop asking questions though!
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|