Pages

Thursday, April 19, 2007

How to compare two fonts in .Net

Which of the two folowing expressions to use when you want to compare two fonts?
a) if (fontA == fontB)
b) if (fontA.Equals(fontB)

Answer
if you want to check whether the fonts have the same family font, same size, same style etc. use the first expression, (a) :
if (fontA.Equals(fontB)
if you want to compare if the reference of the fontA is the same as the reference of the fontB use the second expression, (b):
if(fontA == fontB) or the equivalent expression if ( Font.Equals(fontA, fontB) )

Further reference http://msdn2.microsoft.com/en-us/library/w4hkze5k.aspx

No comments: