Preface:
Yesterday, as always, I posted a post on forums.asp.net, but it was hit by the previous rolling news:
. NET 4.1 Preview-New Base Class Library (BCL) Extension Methods-RFC
Considering the relationship between objective L and 1 st, is it a joke Scott Hanselman gave to everyone, or is it a real official news?
Let's start with "schörörör's cat:
The philosopher Erwin schrödinar has an ideal experiment on quantum theory. The content is as follows (skip is an expert in quantum physics ):
This cat is very pitiful. She (assuming this is a female cat to cause more pity) is blocked in a secret room with toxic food. There is a hammer on the poison bottle. The hammer is controlled by an electronic switch and the electronic switch is controlled by a radioactive atom. If the nucleus decay, then alpha particles will be released, the electronic switch will be triggered, the hammer will fall, the poison bottle will be broken, and the cyanide gas will be released, and the female will no doubt die.
Before the measurements were made, the state of a particle was blurred and in a mixture of possibilities, Copenhagen says. For example, when a radioactive atom decay is completely probabilistic. As long as it is not observed, it will be in the superposition of decay/non-decay. Only when it is indeed measured, it will randomly choose a state to appear, so that, because we did not observe, so the atom in the box is in the superposition state of decay/non-decay. The status of the atom is unknown, so the cat's status is also unknown. Only when we open the box to check whether the thing is final: either the cat is lying in the box and dead, or it's just screaming. The problem is, before we open the box, what is the status of the cat? It seems that the only possibility is that it is in the same overlay state as our atom, and the cat was stuck in a dead/living mix.
The cat of schörörör's expresses an "uncertain state" in the real world. Can we also reflect an "uncertain state" in OO programming?
That is to say, when an object is not used, it is a superposition of "String" and "Cat". When we use it, it can be either String or Cat:
In programming, type conversion is often rigorous for a long time: A String object "hello123" cannot be directly expressed as an Int value, this usually results in an exception for type conversion.
StringOr <TOther>
OK. Let's take a look at the generic class provided by Daniel:
Namespace System. QuantumEntanglement {
Public class StringOr <TOther> {
Public StringOr (string stringValue, TOther otherValue );
Public string StringValue {get ;}
Public TOther OtherValue {get ;}
}
}
This StringOr class wraps String together with a different type and has two get accessors, which return two types of values respectively. It is also very easy to use:
You can access the OtherValue attribute to easily obtain other representations of the userInput object.
SchrodingOr <TDead, TAlive>
Next let's take a look at this class:
Namespace System. QuantumEntanglement {
Public class SchrodingOr <TDead, TAlive> {
Public SchrodingOr (TDead dead, TAlive alive );
Public TAlive Alive {get ;}
Public TDead Dead {get ;}
}
}
Similar to the StringOr class above, SchrodingOr also provides the "TAlive" and "TDead" forms for objects through generics. That is to say, this is a c # version of "schörör's cat ".
In this case, whether a SchrodingOr object is "TAlive" or "TDead" needs to be determined by "Observer:
Just like a cat in the middle, this uncertain state is fully manifested in our code:
System. QuantumEntanglement technology preview:
Current. NET 4.1 Library is in early preview, but the product group decides to release this System. the QuantumEntanglement Class Library source code and unit test source code can be used to collect user feedback. We can download it here:
Class library with unit tests (requires Visual Studio 2008 Professional and higher)
If you have any questions, you can contact: string.or@microsoft.com.
Link of the information source (some image sources ):
Http://weblogs.asp.net/leftslipper/archive/2009/04/01/the-string-or-the-cat-a-new-net-framework-library.aspx
Http://blog.wekeroad.com/blog/cool-extension-methods-for-new-stringor/
Http://lostintangent.com/2009/04/01/string-input-handling-quantum-mechanics/
Http://www.hanselman.com/blog/NET41PreviewNewBaseClassLibraryBCLExtensionMethodsRFC.aspx