Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / clr / src / BCL / System / Collections / CaseInsensitiveComparer.cs / 1 / CaseInsensitiveComparer.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: CaseInsensitiveComparer
**
**
**
============================================================*/
namespace System.Collections {
//This class does not contain members and does not need to be serializable
using System;
using System.Collections;
using System.Globalization;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class CaseInsensitiveComparer : IComparer {
private CompareInfo m_compareInfo;
private static CaseInsensitiveComparer m_InvariantCaseInsensitiveComparer;
public CaseInsensitiveComparer() {
m_compareInfo = CultureInfo.CurrentCulture.CompareInfo;
}
public CaseInsensitiveComparer(CultureInfo culture) {
if (culture==null) {
throw new ArgumentNullException("culture");
}
m_compareInfo = culture.CompareInfo;
}
public static CaseInsensitiveComparer Default
{
get
{
return new CaseInsensitiveComparer(CultureInfo.CurrentCulture);
}
}
public static CaseInsensitiveComparer DefaultInvariant
{
get
{
if (m_InvariantCaseInsensitiveComparer == null) {
m_InvariantCaseInsensitiveComparer = new CaseInsensitiveComparer(CultureInfo.InvariantCulture);
}
return m_InvariantCaseInsensitiveComparer;
}
}
// Behaves exactly like Comparer.Default.Compare except that the comparison is case insensitive
// Compares two Objects by calling CompareTo. If a ==
// b,0 is returned. If a implements
// IComparable, a.CompareTo(b) is returned. If a
// doesn't implement IComparable and b does,
// -(b.CompareTo(a)) is returned, otherwise an
// exception is thrown.
//
public int Compare(Object a, Object b) {
String sa = a as String;
String sb = b as String;
if (sa != null && sb != null)
return m_compareInfo.Compare(sa, sb, CompareOptions.IgnoreCase);
else
return Comparer.Default.Compare(a,b);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- VariableQuery.cs
- DataSourceCache.cs
- StorageRoot.cs
- DataServiceConfiguration.cs
- Propagator.cs
- ActivityScheduledRecord.cs
- GroupDescription.cs
- TextServicesCompartmentContext.cs
- PopOutPanel.cs
- StylusPointPropertyInfo.cs
- ProjectionPlanCompiler.cs
- TextTreeUndo.cs
- TextWriter.cs
- ConfigurationManagerInternal.cs
- DSACryptoServiceProvider.cs
- ComponentTray.cs
- SpellerInterop.cs
- DebuggerAttributes.cs
- SchemaConstraints.cs
- DataSysAttribute.cs
- CoreSwitches.cs
- FormsAuthenticationTicket.cs
- Int32Converter.cs
- ProtocolsConfigurationHandler.cs
- EventBookmark.cs
- Underline.cs
- RoamingStoreFileUtility.cs
- ToolStripPanelCell.cs
- ServiceParser.cs
- Msmq4PoisonHandler.cs
- BufferedWebEventProvider.cs
- ErrorRuntimeConfig.cs
- PermissionToken.cs
- CharEnumerator.cs
- NativeObjectSecurity.cs
- ProcessHostMapPath.cs
- WebPermission.cs
- Activator.cs
- XmlSerializerVersionAttribute.cs
- SqlProviderServices.cs
- ElapsedEventArgs.cs
- Animatable.cs
- RightsManagementEncryptedStream.cs
- XmlProcessingInstruction.cs
- DataBoundControl.cs
- SocketConnection.cs
- MULTI_QI.cs
- EntityDataSourceDesignerHelper.cs
- __ConsoleStream.cs
- PartitionResolver.cs
- ConsumerConnectionPoint.cs
- XmlAnyElementAttributes.cs
- BufferModeSettings.cs
- RequestCache.cs
- ApplicationHost.cs
- WebPartMovingEventArgs.cs
- ArraySortHelper.cs
- DataStreamFromComStream.cs
- WebPartManagerInternals.cs
- DBAsyncResult.cs
- SR.cs
- Regex.cs
- ArglessEventHandlerProxy.cs
- ListViewInsertEventArgs.cs
- XmlSchemaAttributeGroupRef.cs
- Int16Storage.cs
- PropertyDescriptorComparer.cs
- MonthChangedEventArgs.cs
- AnnotationStore.cs
- QueryContinueDragEvent.cs
- DataControlPagerLinkButton.cs
- ValueConversionAttribute.cs
- QueryStringParameter.cs
- GridViewAutomationPeer.cs
- TreeNodeSelectionProcessor.cs
- DocumentXPathNavigator.cs
- CopyOnWriteList.cs
- RuntimeConfigLKG.cs
- Win32Exception.cs
- Decoder.cs
- NativeCppClassAttribute.cs
- MyContact.cs
- ReadOnlyKeyedCollection.cs
- MethodRental.cs
- AesCryptoServiceProvider.cs
- SoapRpcMethodAttribute.cs
- StringUtil.cs
- CommentGlyph.cs
- SplitterDesigner.cs
- Activator.cs
- ToolboxItemCollection.cs
- UnsafeNativeMethods.cs
- XLinq.cs
- TreeBuilderBamlTranslator.cs
- Splitter.cs
- DataGridViewCheckBoxCell.cs
- InlineCollection.cs
- BlobPersonalizationState.cs
- ClrProviderManifest.cs
- SafeSecurityHelper.cs