|
Haha, I did exactly that, but then found it to take up more characters than the other method, to be less clear, and to potentially take up more processing time (the strig concatenation). If you make both words lowercase, you can get it down to exactly the same number of characters as the one I posted, but it still has the other issues. But nice try.
|
|
|
|
|
correct.
MessageBox.Show((tb1.Text.Length>0)==(tb2.Text.Length>0)?"OK":"!OK");
|
|
|
|
|
I had a nice long reply I was working on, but my Internet decided to go down just as I posted it. So, lucky for you, you get the short version instead:
((a.L>0)==(b.L>0)).S();
|
|
|
|
|
why would you need a long reply to come up with a succinct code snippet?
Anyway, with a real pre-processor, it is trivial:
T
|
|
|
|
|
If my Internet didn't go down, you'd know.
Why use a letter with such a high ASCII value? This seems more optimal:
A
As a bonus, your left pinky is already on that letter.
|
|
|
|
|
I suspect the energy saving comes from having fewer 1-bits.
|
|
|
|
|
if((!String.IsNullOrEmpty(BP_S.Text) && !String.IsNullOrEmpty(BP_D.Text)) || (String.IsNullOrEmpty(BP_S.Text) && String.IsNullOrEmpty(BP_D.Text)))
Mark as answer if its really satisfies ur query !!!!
modified on Saturday, April 10, 2010 8:52 AM
|
|
|
|
|
Now that's interesting, because that wouldn't allow you to fill in the second textbox if you didn't fill in the first as well - and he never said anything about that. Basically it's the same as aspdotnetdev's, but in the least-succinct way.
|
|
|
|
|
harold aptroot wrote: he never said anything about that
FYI, my impression is that the OP wants either both to be filled in or neither to be filled in. Filling in one without filling in the other is not allowed.
|
|
|
|
|
Ok, I think he just said that he wants a truth table like this:
D S result
0 0 1
0 1 1
1 0 0
1 1 1
IOW "everything is OK except skipping the second textbox after filling in the first"
The smallest formula for that truth table is, AFAIK, (¬D)v S (where v is OR)
Or maybe I'm just taking his explanation too literally..
|
|
|
|
|
The OP said "one textbox is not null then the other should not be null as well". Order of the textboxes is never stated or implied. So "0 1" and "1 0" should have the same result ("0").
|
|
|
|
|
Interpretation.
The OP should reply and clear this up..
|
|
|
|
|
harold aptroot wrote: The OP should reply and clear this up
The OP already did that:
jrahma wrote: if the user entered BP_S then he MUST enter BP_D
similarly, if the user entered BP_D then he MUST enter BP_S
but user can leave both BP_S and BP_D as NULL
Let's break that down...
jrahma wrote: if the user entered BP_S then he MUST enter BP_D
That means:
If the first textbox contains some text, the second textbox must contain some text.
jrahma wrote: if the user entered BP_D then he MUST enter BP_S
That means:
If the second textbox contains some text, the first textbox must contain some text.
jrahma wrote: user can leave both BP_S and BP_D as NULL
That means:
If both are empty, that is fine.
What all of that means:
It is valid for both to be empty or both to contain text, but it is not ok for just one but not the other to contain text.
That is my interpretation. But it is also the correct interpretation. I think the OP has everything he needs, but feel free to ask him if you don't think that's the case.
|
|
|
|
|
Oh lol. I forgot about that post
|
|
|
|
|
You should first read the chain of responses before reply to anything.
Yes its not in succinct way but I wrote it for people like you to understand who cant do proper requirement gathering or forgets about what the requirement is
|
|
|
|
|
Meh.. it was 3AM both times I posted that sh*t
|
|
|
|
|
I'm having a hard time deserializing old versions of a class after adding a new member. I've written a toy program that's the simplest possible example of this problem. Maybe someone else might notice what I'm doing wrong.
I have a class with one member: A System.Drawing.Color:
[Serializable]
public class SerialObj
{
public System.Drawing.Color color;
}
The following code serializes/deserializes it with no problem:
SoapFormatter formatter = new SoapFormatter();
formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
formatter.Serialize(myStream, so);
SoapFormatter formatter = new SoapFormatter();
formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
so = (SerialObj)formatter.Deserialize(myStream);
I added an int member, and I'm trying to use the ISerializable interface to handle the different versions. This interface requires a constructor with two special parameters, and a GetObjectData method:
[Serializable]
public class SerialObj : ISerializable
{
public System.Drawing.Color color;
public int number;
public SerialObj()
{
System.Windows.Forms.MessageBox.Show("In empty ctor.");
}
public SerialObj(SerializationInfo info, StreamingContext cntxt)
{
System.Windows.Forms.MessageBox.Show("In full ctor.");
color = (System.Drawing.Color)info.GetValue("color", typeof(System.Drawing.Color));
try
{
number = info.GetInt32("number");
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
void ISerializable.GetObjectData(SerializationInfo inf, StreamingContext cxt)
{
System.Windows.Forms.MessageBox.Show("In GetObjectData.");
inf.AddValue("color", color);
inf.AddValue("number", number);
}
}
It works for serialized new versions with both members. But when I deserialize an old version (without the int), it crashes on the Deserialize call, with the exception: "Top Object cannot be instantiated for element 'color'." It never even calls either constructor.
Can anyone see what I'm doing wrong, or suggest an alternative approach?
Thanks!
Alan
|
|
|
|
|
Try this....
// Version 1.0
[Serializable]
public class SerialObj
{
public System.Drawing.Color color;
}
// Version 2.0
[Serializable]
public class SerialObj
{
public System.Drawing.Color color;
[OptionalField(VersionAdded = 2)]
public int number;
}
// Version 3.0
[Serializable]
public class SerialObj
{
public System.Drawing.Color color;
[OptionalField(VersionAdded=2)]
public int number;
[OptionalField(VersionAdded=3)]
public int solution;
}
|
|
|
|
|
Thanks for the suggestion, but according to this (http://msdn.microsoft.com/en-us/library/ms229752.aspx[^]) the OptionalField attribute doesn't work with the SoapFormatter (just the BinaryFormatter).
Versions have been released using the SoapFormatter, so I can't change it at this point.
|
|
|
|
|
Migounette, I tried your suggestion anyway, and it works with the new versions (both members), but not with the old versions (color member only).
The error message is: "Member at position 0 was null. Parameter name: members".
I don't have any variable named "members", so it must be referring to something internal to .NET.
|
|
|
|
|
|
Hi Alan,
I haven't studied the subject yet, however it so happens I just read a CP thread about this, and it seems you need to use SerializationBinder class. MSDN even holds an example.
|
|
|
|
|
Thanks Luc. I have tried using a custom SerializationBinder (for the formatter.Binder member). It implements a single method, BindToType, which appears to be used repeatedly as a subroutine for the .NET framework serialization, that returns a Type when given a typeName string.
It didn't avoid the error message I'm getting. The error happens after the return from the Binder, with the type that had the added member.
|
|
|
|
|
Hi guys,
I know how single dimensional arrays works but I don't understand at all these GetUpperBound and GetLowerBound methods for multi dimensional arrays. I know somebody would have a very simple way to educate me so i could have a broad smile on my face.
Thanks
string[,] myarray = new string[,] { { "01", "Honda" }, { "02", "GM" }, { "04","Ford"} };
myarray.GetUpperBound(0);
|
|
|
|
|
Look at this msdn article:
[^]
|
|
|
|