System.Xml.NameTable.Add C# (CSharp) Method

Add() public method

public Add ( string key ) : string
key string
return string
        public override string Add( string key ) {
            if ( key == null ) {
                throw new ArgumentNullException( "key" );
            }
            int len = key.Length;            
            if ( len == 0 ) {
                return string.Empty;
            }
            int hashCode = len + hashCodeRandomizer;
            // use key.Length to eliminate the rangecheck
            for ( int i = 0; i < key.Length; i++ ) {
                hashCode += ( hashCode << 7 ) ^ key[i];
            }
            // mix it a bit more
            hashCode -= hashCode >> 17; 
            hashCode -= hashCode >> 11; 
            hashCode -= hashCode >> 5;
            
            for ( Entry e = entries[hashCode & mask]; e != null; e = e.next ) {
                if ( e.hashCode == hashCode && e.str.Equals( key ) ) {
                    return e.str;
                }
            }
            return AddEntry( key, hashCode );
        }

Same methods

NameTable::Add ( char key, int start, int len ) : string

Usage Example

 private static XmlNameTable CreateNameTable()
 {
     XmlNameTable table = new System.Xml.NameTable();
     table.Add(string.Empty);
     table.Add("http://www.w3.org/2000/xmlns/");
     table.Add("http://www.w3.org/XML/1998/namespace");
     return table;
 }
All Usage Examples Of System.Xml.NameTable::Add