/* ANY-LICENSE V1.0 ---------------- You can use these files under any license approved by the Open Source Initiative, preferrably one of the popular licenses, as long as the license you choose is compatible to the dependencies of these files. See http://www.opensource.org/licenses/ for a list of approved licenses. Author: Martin Furter Project: Modified: 2019 */ using System; public abstract class Format { public string fmt; public Format( string _f ) { fmt = _f; } public void print_line() { Console.WriteLine( "{0}", format_line() ); } public string format_line() { string i = value_raw().PadRight( 20 ); string f = fmt.PadRight( 20 ); string s = value_fmt(); return string.Format( "{0} {1} '{2}'", i, f, s ); } public abstract string value_raw(); public abstract string value_fmt(); } public class IntFormat : Format { public int i; public IntFormat( int _i, string _f ) : base( _f ) { i = _i; } public override string value_raw() { return String.Format( "{0}", i ); } public override string value_fmt() { return String.Format( fmt, i ); } } public class StringFormat { [STAThread] static public void Main( string[] args ) { Format[] fmts = new Format[]{ new IntFormat( 42, "{0}" ), new IntFormat( -23, "{0}" ), new IntFormat( 42, "{0:D4}" ), new IntFormat( -23, "{0:D4}" ), new IntFormat( 42, "{0:x4}" ), new IntFormat( 42, "{0:X4}" ) }; foreach( Format fmt in fmts ) { fmt.print_line(); } } }