Format and iformattable stringformat

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: value of the current instance as specified. IDisposable: Provides explicit control of releasing resources 13 System Namespace IFormattable String.Format and IFormattable String.Format String.Format(“Please order {0} widgets at {1} each.”, i, f); String.Format(“{0:U}”, DateTime.Now); Implement IFormattable for custom formatting of your own types interface IFormattable { String Format(String format, IServiceObjectProvider sop); } Use IServiceProvider to get culturally-aware delimiters for numbers and date/time Implement ICustomFormatter to override default formatting for built-in types System Namespace IDisposable Example class class ResourceWrapper : IDisposable { private IntPrt handle; // Pointer to an external resource private OtherResource otherRes; bool disposed = false; private void freeState () { // Free your own state if (!disposed) { CloseHandle (handle); dispose = true; } } // Free your own state, call dispose on all state you hold, // and take yourself off the Finalization queue public void Dispose () { freeState(); OtherRes.Dispose(); GC.Suppress.Fi...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online