|
Actually, the operators are visible to all languages. They are actually defined as methods with names such as op_Equality, op_Inequality, etc. and other languages can use their operators to call those methods.
You are on the right track as far as qualities of equality, though strings are a weird case where there are quite a few different "levels" of equality. My response below explains what I see as reasons for different equality methods if you are interested.
|
|
|
|
|
There are so many ways to check equality because there are so many situations that need to be handled. Jared Parsons wrote a nice set of articles that explain some of this topic. The link is to the last article in the set, each of which links to the article before (in typical blog fashion).
One reason to have more than just the operator is because the operator must be a static method. This means that which operator to call depends on the compile-time type of the variable instead of the using the runtime-type like a virtual method (such as Equals) would. Also, because they are static, operators cannot be defined on interfaces. So if you need equality methods on an interface, you have to have instance methods. An advantage of the IEqualityComparer interface is that you can have a different condition for "equality" in different situations for the same type. In one case, you may only check the name, but in another you may want to check both the name and the age. This would be impossible with just the operator or overriden virtual method, but is possible to do with the extra interface. (A similar reasoning can be given for having both IComparer and IComparable for sorting.)
C# has a particularly nasty problem when it comes to == vs .Equals(). In C#, if you write if (a == b) { ... } when there is no overloaded operator for the types of variables a and b, the compiler will check to see if the are both references to the same object. In VB however, writing If a = b Then ... when there is no overloaded operator, a compile error will occur. To see if a and b are references to the same object, you use the Is and IsNot operators.
Collection<Derived>.IndexOf has to use IEquatable<Derived> because it was written without any knowledge of what your classes will be. The alternative would involve a bunch of messy reflection code that would cause horrible performance and would probably not be useful in most situations. All the other places where you are using == and Equals, the compiler knows about and will use your methods since they are the best match. Out of curiosity, did you both implement the Equals for IEquatable<Base> and override the Equals from object?
public class Base : IEquatable<Base>
{
public static bool operator==(...)
{
...
}
public bool Eqauls(Base other)
{
}
public override bool Equals(object obj)
{
}
}
If you did, I would expect that before you implemented IEquatable<Derived> , the default algorithm used by IndexOf should have called the override and gotten what you wanted.
|
|
|
|
|
wow. there seems to be a lot hidden behind a simple == concept.
I'll have to read your reply a couple more times.
It does shed some light on this thread[^].
Thanks.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi Gideon,
Thanks for the explination, I think I fully understand it now, but I will do more reading on it.
All I did was to override == and Equals in my base class (which obviously did not give me the correct behaviour), then after much searching I implemented IEquatable<Derived> on my derived class and it worked fine so I stopped working on it.
Should I try to implement IEquatable<Base> and see if that gives the correct behaviour? (The attributes I'm comparing on is part of the Base, infact I use the overloaded == to compare)
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
I’m trying to get a list of all the characters in a specific language (e.g. Chinese or Spanish) in order to display or print them. I couldn’t find any kind of class or method that provides it. I’m there is one (must be), but I just can’t find it.
Thanks,
Sharon.
|
|
|
|
|
For ASCII fonts you can loop till 255 and get each character. Work with char.ConvertFromUtf32()[^] method.
For Unicode fonts, you need to get the code chart from http://unicode.org/[^] and work with the same function. But this will not give you whole characters as in unicode several complex letters are created as combination of other characters.
Here is an example to get a character form a code point.
string cp = "312D";
int code = int.Parse(cp, System.Globalization.NumberStyles.HexNumber);
string uString = char.ConvertFromUtf32(code).ToString();
|
|
|
|
|
Thanks for the quick response.
Your solution will, indeed’ solve my problem. But I want a solution for all languages, since I don’t know the languages that are installed on the user’s computer, and I don’t want to type all Unicode tables (obviously I want it automatic).
Like I said, I believe that there is some way to do it using the .NET framework. I hope I’m not wrong.
Thanks.
|
|
|
|
|
Sharon Eden wrote: I believe that there is some way to do it using the .NET framework.
I don't think so.
As I said, if you are dealing only with ASCII fonts, you are in luck. Suppose if you want to show all characters in Spanish on a textbox, you get a Spanish font and set that as textbox's font. Loop till 255 and print each character to the textbox. You can see the characters getting printed in Spanish. If the font used doesn't provide all characters, this method will fail.
|
|
|
|
|
it seems that you are right and this function does not exist.
let me ask you this, it there a way to get the Unicode range of the language characters when you have the CultureInfo class? in some cases different CultureInfo classes use the same Unicode character range (for example English-US and English-UK).
|
|
|
|
|
Hi,
I'm facing this same problem. I wanted to get all the characters specific to culture. It is unfortunate that .NET framework doesn't have a straight-forward solution to retrieve those.
Did you find any alternative approach on this? If so, please mail to mail2sen00@yahoo.com.
Any help on this would be highly appreciated!
Many thanks,
Senthil.
|
|
|
|
|
I'm sorry, no good new from me. unfortunately i couldn't find any other way then predefine the range of any desired culture manually in the code. that means that i probably have some errors and missing characters and it is not automatic procedure for any kind of language, but only for those I've defined.
|
|
|
|
|
|
What's the best way to convert a string containing Unicode characters like accented letters to the most logical ASCII representation? Converting to ASCII turns all non-ASCII characters into question-marks, which doesn't seem very helpful. The best approach I can figure is to concatenate each character of the string onto each letter a-z, and then check whether the resulting string sorts between that letter and the next higher character using the default culture. If a letter is found where the string sorts properly, then check whether the string is identical to the uppercase version of itself. If not, the string is a letter a-z; otherwise it's a letter A-Z.
Rather a clunky way to do things, but I don't know of any better fundamental method (obviously performance can be improved considerably if one caches the results, but I know of no better way to determine them initially). Is there any good method?
|
|
|
|
|
Sub Connectionopen()
Try
oraConnection = New OleDb.OleDbConnection(strConnectionString)
If (oraConnection.State = ConnectionState.Closed) Then
oraConnection.Open()
End If
Catch ex As Exception
'MsgBox(ex.ToString & "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!open")
End Try
End Sub
**** i want to put a timer on
oraConnection.Open()
that timer will check in 10 seconds either connection is open or closed.and i want to check this before oraConnection.Open()
thxxx
|
|
|
|
|
rashid2009 wrote: **** i want to put a timer on
oraConnection.Open()
that timer will check in 10 seconds either connection is open or closed.and i want to check this before oraConnection.Open()
Why ? What is the purpose of the Timer over here ? Just Set ConnectionTimeOut Properties for it.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Sir, i want a detailed explanation with screen shots of Master Pages, User Controls and Authorization and Authentication in ASP.NET 2.0.
Sir , I also want a detailed difference between GET AND POST METHOD.
|
|
|
|
|
Sir, what is stopping you from buying a book? Read this[^] before you post questions.
|
|
|
|
|
Swastik Das wrote: Sir, i want a detailed explanation with screen shots of Master Pages, User Controls and Authorization and Authentication in ASP.NET 2.0.
Sir , I also want a detailed difference between GET AND POST METHOD.
I want Carmen Electra to come round to my house and give me an oiled rubdown tonight. It looks like we're both going to be disappointed.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: I want Carmen Electra
I thought that was a ladies' hair dryer
|
|
|
|
|
So, she blows???
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
what is the code to attach the database to data grid using List box
|
|
|
|
|
jjppyy wrote: what is the code to attach the database to data grid using List box
Probably in here[^] somewhere.
|
|
|
|
|
It doesn't exist; you'll have to write it.
|
|
|
|
|
hiiiiii
I m running a .exe from asp.cs page .job of exe is to generate images in a folder which is already there in my application.exe is running and woking properly when i m running the application in my system at localhost.but when i m running my application in the clint side on there application server then exe is running but it is not doing any thing ,i have seen in my
task manager that exe runs but take no cpu storage.
its really urgent........
thanks in advance......
|
|
|
|
|