|
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:
[^]
|
|
|
|
|
Every array has at least 1 dimension, for instance:
string[] x1 = new string[] {...} // is 1 dimensional
string[,] x2 = new string[,] {...} // is 2 dimensional
string[,,] x3 = new string[,,] {...} //is 3 dimensional
Each dimension has upper and lower bounds, which in most cases is easiest to think about as a capacity, since the lower bound is almost always 0.
The GetUpper and LowerBounds functions help you get the bounds (lowest possible index to highest possible index) for the given dimension, so...
Here we are creating a 1 dimentional array with a capacity of 5 elements.
string[] x1 = new string[5];
now we pass the target dimension (0 index based) to the function...
GetLowerBounds(0) would say 0.
GetUpperBounds(0) would say 4.
Why does upper bounds say 4? Because the bounds functions are returning 0 based indexes, thus, the capacity is 5, and the 5 indexes of each 'space' are 0,1,2,3, and 4.
If we were to do this:
GetLowerBounds(1) or GetUpperBounds(1) we would get an exception, because our array has only 1 dimension (thus we would pass index 0).
More reading here:
http://msdn.microsoft.com/en-us/library/system.array.getlowerbound.aspx[^]
http://www.java2s.com/Tutorial/CSharp/0220__Data-Structure/ArrayGetLowerBoundGetUpperBound.htm[^]
|
|
|
|
|
When you use an initializer list, the outermost array is the first dimension and the innermost array is the last dimension. So, myarray[0,0] is "01" and myArray[0,1] is "Honda" (notice that I didn't change the index for the first dimension). Another way of seeing it is that the first index of the first dimension points to {"01", "Honda"}... you have to specify an index into the second dimension to get either "01" or "Honda".
In the example you gave, the first dimension (GetUpperBound(0)) has an upper bound of 2 (because there are 3 items, the third item would be referenced by index 2). The second dimension (GetUpperBound(1)) has an upper bound of 1 (because there are 2 items in each subdimension, the second items are referenced by index 1).
If that doesn't make sense, play with it a bit and you'll eventually get it via osmosis.
By the way, in C# the lower bound should always be 0.
|
|
|
|
|
aspdotnetdev wrote: you'll eventually get it via osmosis.
osmosis? that's what doesn't happen when you put your C# book under your pillow and hope it will "sink in" while you're asleep.
|
|
|
|
|
Osmosis is when you hear Arnold say "My CPU is a neural net processor -- a learning computer" and only understand what that means years later when you understand the underlying concepts from different perspectives.
|
|
|
|