Programming the .

NET Compact Framework

Appendix A

Appendix A
Hungarian for .NET Programs
Version 1.0
September 5, 2003
By: Paul Yao and David Durant
Time is a software developer's most precious resource. For that reason, anything
that can help save time – at any phase of the project – while maintaining or increasing
productivity is a good thing. When we started to work on this book1, we began by
collaborating on a set of standards to minimize the differences between our coding
styles. As the project moved forward, we refined and updated various elements of this
file. We offer this set to you, our readers, as a starting point for your own coding
standards. (To get an editable copy of this file in Microsoft Word format, email
info@paulyao.com.)
After the book is published, we expect to continue updating the various elements of
this file and maintaining it on our web site (http://www.pauyao.com), and welcome your
comments and suggestions. To submit a comment or suggestion, click on any hyperlink
in a machine-readable version of this file. Each hyperlink is numbered, to help us
understand the specific part of the document which triggered your response. For general
comments, general suggestions, or new types to include, click on this link: [Comment A.1]

Goals:
1
2

3
4

Enhance code readability. [Comment A.2]
Make elements of the sample code – classes, properties, methods,
events, fields – clearly distinct from those elements of the Compact
Framework. [Comment A.3]
Work equally well in both C# and Visual Basic .NET. [Comment A.4]
Establish standards which would work equally well in Compact
Framework code as well as desktop .NET Framework code. [Comment
A.5]

Guidelines
These standards are for a coding project that exclusively uses Microsoft's .NET
technology, specifically the C# and VB .NET languages. These are, in short,
1

The books mentioned above (for the PDF version of this file) are: Programming the .NET
Compact Framework in C# and Programming the .NET Compact Framework in VB.NET, both by
Paul Yao and David Durant, and both published by Addison-Wesley.
© Copyright 2002 Paul Yao & David Durant
All Rights Reserved

1 of 14

9/10/2003 2:24 PM

– are easily understandable to programmers who are already familiar with .NET is not. the naming scheme described here works with the default names provided by the forms designer. Because one of the design goals of the Compact Framework was to maintain consistency with the desktop framework.9] Avoid terse abbreviations . The single exception to this rule involves the names for constants. These standards were created with the following guidelines in mind: [Comment A.7] Hungarian Naming – Although this style of naming has lost favor with some. programmers have no interest in changing these.NET projects. For that reason. our naming standard relies heavily on Hungarian. SQL data adapters. with a few exceptions which are noted later.both for prefixes and for variable names – in favor of making them more meaningful.Programming the . etc. the name for TextBox is text rather than the shorter. we avoided any convention that relied on distinguishing upper-case from lower-case names. some of which can be left alone but others are likely to change. it has always been one that we like. You can read the details of these guidelines here: [Comment A. this approach means that these guidelines can be extended as future versions of the Compact Framework become available.asp. [Comment A. txt.Forms Company Name Technology Name 2 of 14 9/10/2003 2:24 PM . the problem they create is that they are somewhat hard to remember.13] Type Containing Elements Convention Notes and Examples Namespace [Comment A. and for members of enumerations.WindowsCE. [Comment A. In many cases. [Comment A.NET documentation provides some guidelines to start with.6] • • • • • Case Insensitive – C# is case-sensitive." This strict set of rules helps insure that new class libraries – custom controls. Of particular interest is a section titled "Design Guidelines for Class Library Developers. Understanding these guidelines will help you write code that is generally more readable and maintainable than if you did not. Rather than provide the copious detail of those design guidelines. label2. label3.NET Naming Standards The Microsoft . For example. This book generally follows these guidelines.12] http://msdn. [Comment A. but less understandable. For example. as such we avoid naming things that are not in the Compact Framework. [Comment A.10] Include elements in the Compact Framework. While terse names make it easier to type.8] The Visual Studio . which shall be all upper-case. we have summarized the key points here.14]s Combine the following elements together for namespace names in public libraries: Example: • • © Copyright 2002 Paul Yao & David Durant All Rights Reserved Microsoft.NET Compact Framework Appendix A recommendations that apply specifically to .11] .NET conventions. but VB .microsoft. [Comment A. For that reason. As much as possible. The focus of this book is the Compact Framework.com/library/en-us/cpgenref/html/cpconnamingguidelines. labels on forms are given names like label1. etc.NET forms designer suggests names.

Programming the .24]s • © Copyright 2002 Paul Yao & David Durant All Rights Reserved Use suffix of "EventHandler" for event handler itself Provide protected method OnXXX where XXX = event name Use verbs or verb phrases 3 of 14 Example: HelpFileAttribute. TextBox Examples of derived class names: • • DateTextBox MainForm Contained Elements Attribut [Comment A.NET Compact Framework Appendix A Type Convention Notes and Examples Clas [Comment A.20]d • Event Name [Comment A. Do not use "Enum" in name of enumeration Use suffix of EventArgs for event argument class • Event Handle [Comment A.15]s • • • Examples of nouns as class names: • Feature Design Use nouns or noun phrases for classes For derived classes.18]s • Use suffix of "Attribute" for custom attribute classes. Interfac [Comment A. or adjectives that describe behavior.19]r • Event Handling Metho [Comment A. Use nouns. AuthorAttribute Examples: • CombineMode • FontStyle • GraphicsUnit • Keys • DayOfWeek • FileShare Examples: • RowUpdatedEventArgs • KeyEventArgs • MouseEventArgs Examples: • TreeViewEventHandler • KeyEventHandler Examples: • OnParentChanged • OnRowUpdated • OnKeyDown • OnMouseMove Examples: • ParentChanged • EnabledChanged • GotFocus • LostFocus Examples: • ArithmeticException • DivideByZeroException • IndexOutOfRangeException Examples: • ICollection • IComparer • IDictionary • IEnumerable • IEnumerator • IList Examples: • Activate 9/10/2003 2:24 PM . create compound names for classes by appending base class name at end of new class name.21]s • Use verbs for event names Exception [Comment A. • Control.23]e • Use prefix of "I" for interface names.16]e • Enumeratio [Comment A.22]s • Use suffix of "Exception" for exception names.17]n • Event Argument Clas [Comment A. noun phrases. • Method [Comment A. Form.

" – Note from Dr.30] Rather than repeat all the details that are so well described in this article. you will not find an ISO standards committee – or.28] • • Use descriptive parameter names Do not use Hungarian naming Use type-based parameter names sparingly Use noun or noun phrase Do not use Hungarian naming Use noun.29] "It came to be known as "Hungarian notation" because the prefixes make the variable names look a bit as though they're written in some non-English language and because Simonyi is originally from Hungary. [Comment A. a style. Where you get the greatest benefits from Hungarian are on projects where all agree to use the same set of types.31] Hungarian naming is not a standard.26] • • Static Field [Comment A. [Comment A. noun phrases.NET Compact Framework Type Method Parameter [Comment A. In other words.25]s Appendix A Convention Notes and Examples • • Close • Invoke • ShowDialog Example: • • Property [Comment A. While there are many lists of suggested prefixes – including this appendix – none claim to be the definitive one that supersedes all others.asp.27] • Fields [Comment A. because with few exceptions every programming project has its own unique set of types. instead.com/library/enus/dnvsgen/html/hunganotat. Lists (like this one) that call themselves "standards" are really just starting points for project-specific data types. 1999.microsoft. An MSDN Technical Article gives this explanation for how this approach got its name: [Comment A.32] Hungarian naming is. Gui.33] © Copyright 2002 Paul Yao & David Durant All Rights Reserved 4 of 14 9/10/2003 2:24 PM . [Comment A. [Comment A. an ANSI / IEEE / ECMA committee – that dictates what prefixes you can and cannot use. or noun abbreviations for the name Use Hungarian naming Do not use Hungarian naming – good names describe semantics not type Examples: • BackColor • Font • Text • Width Examples: Hungarian Naming Hungarian naming refers to a style of creating meaningful variable names. It provides a common language so that any team member can look at any code and understand it.Programming the . here is a link to a reprint of Charles Simonyi's original white paper on this naming convention for readers who wish to learn more: http://msdn. for that matter. November.

strLastName.NET text editing windows. a feature of the Visual Studio . The "old-fashioned" way to find the variable name would be to do a search. He states that the disciplined use of Hungarian naming – and a project-specific set of types and associated Hungarian prefixes – allowed him to transfer to the Excel team during a crunch period and be productive very quickly. IntelliSense is. Figure B-1 shows how the IntelliSense window showing the available data members that starts with a "str" prefix. We do so because we find it makes our code more readable. By typing this. [Comment A. strPostalCode. When you get there.34] This Book We use Hungarian naming throughout this book for data types. and therefore more understandable. Another alternative is to ask IntelliSense to help you. strAddress. you might find a list of string names defined like this: [Comment A.37] string string string string string string strFirstName.Programming the . strCity. suppose you are writing some code and need to know the name of a string variable that is a data member of the class you are writing.36] For example. or to scroll to the top of your source file (or wherever you normally put such things). you give IntelliSense enough details to help you remember the specific name that you were looking for. [Comment A.38] Figure B-1 Hungarian Naming helps IntelliSense remind you of variable names © Copyright 2002 Paul Yao & David Durant All Rights Reserved 5 of 14 9/10/2003 2:24 PM .NET Compact Framework Appendix A We have a friend who used to work at Microsoft. of course. strState.str in the text editor window. it pops up with possible choices for the next part of an operation. Just about every time you type a dot operator. [Comment A.35] The use of Hungarian also provides another important benefit: it allows you to quickly find names in an IntelliSense list. [Comment A.

We also found that the Compact Framework itself uses m_ for all of its private data.EXE.Decimal decimal © Copyright 2002 Paul Yao & David Durant All Rights Reserved 6 of 14 9/10/2003 2:24 PM . Here is an example: [Comment A.40] The Forms Designer creates private data members for you – one for each control created in a form. the m_ prefix prompted the most discussion.NET Alias Size Prefix System.NET-compatible. This helps us instantly distinguish public data from private data.NET-based technologies. } } The user of this class always uses the public bThreadContinue property. We both found it useful.41] While assembling this set of standards.DateTime [Comment A. these are marked as "not CLScompliant. The following table includes only CLS-compliant types.Boolean bool Boolean 1 byte b char Char 2 bytes ch Date 8 bytes date Decimal 16 bytes dec [Comment A. [Comment A. We do not use the m_ prefix for such private data members. but wanted to make sure it would be reasonable for Compact Framework code. C# supports types outside this specification. which are all not documented. We found it widely used in pre-. [Comment A. // Continue flag. which gets translated into the private m_bThreadContinue only visible to our class. } set { m_bThreadContinue = value. the shared source code implementation of the Common Language Infrastructure (CLI). including C++ projects (for the MFC class library and the ATL template library). and in Active Server Pages. [Comment A.NET documentation.44] .43] Hungarian Prefixes for CTS Value Types The Common Type System (CTS) defines a set of types that all languages must support to be . we non-CLS-compliant types. In the .Char [Comment A. { get { return m_bThreadContinue. but which become visible with a tool like ILDASM. public bool bThreadContinue // Continue property. Visual Basic. Where it is particularly helpful is in allowing a public property and an associated private data member with the same name – the only difference being the private data member has the m_ prefix.Programming the .42] What convinced of its applicability to the Compact Framework was its use in various .39] private bool m_bThreadContinue.47] System. [Comment A." To enhance code portability. including Rotor.NET Class C# Alias Visual Basic . [Comment A.45] System.NET Compact Framework Appendix A The “m_” Prefix for Private Data A variation to the Hungarian style that we adopt in this book is the use of an additional prefix – m_ – for private class data members.NET technologies. most of which are unsigned types.46] System.

iFont. © Copyright 2002 Paul Yao & David Durant All Rights Reserved 7 of 14 9/10/2003 2:24 PM . str [Comment A.62] Index for loops [Comment A.50] System.51] System. cchSearchBuffer e e – the standard event argument for all event handlers.56] Hungarian Prefixes for System Classes [Comment A.Single float Single 4 bytes sin double Double 8 bytes dbl 16 bytes guid [Comment A.49] System.Programming the . ex ex – the standard exception argument for all exceptionhandlers i iItem.Double [Comment A.52] Platform-Specific Pointer or Handle Types System.Byte byte Byte 1 byte byt short Short 2 bytes sh int Integer 4 bytes i long Long 8 bytes l 4 bytes iptr2 [Comment A.Int32 [Comment A.53] FLOATING POINT TYPES System.55] OTHER TYPES System.Int64 [Comment A. objItem.59] Count of characters [Comment A.64] String [Comment A. we use the prefix for the type being represented by the IntPtr variable. strFileName. cbLength cch cchMaxName. Instead.61] Exception [Comment A. This accomplishes the goal of making our code more readable and to reduce the coding errors that arise from misusing variables.48] INTEGER TYPES System. we do not use this prefix for IntPtr.NET Compact Framework Appendix A [Comment A.IntPtr [Comment A. iFile obj objDebugInput.63] Object [Comment A.Guid [Comment A.Int16 [Comment A.60] EventArgs [Comment A.54] System. a Win32 window handle will have a prefix of hwnd instead of iptr. objCollectionStart str strPath.65] 2 Generally speaking.57] Class Prefix Examples Count of bytes cb cbReturnBuffer. For example.

// Integer ArrayList ali.72] HashTable [Comment A. ai[1] = 2. comboTaxSettings [Comment A. strbldErrorLog decode decodeFileBuffer.75] Hungarian Prefixes for Microsoft.79] © Copyright 2002 Paul Yao & David Durant All Rights Reserved 8 of 14 9/10/2003 2:24 PM . queueWaitingList stack stackFunctionCall.78] ComboBox [Comment A. chkCloseWhenDone combo comboStates.77] CheckBox chk chkWordWrap. deleAddItem [Comment A. bitarrCollectionType hash hashFileNames. ali. A.Forms Classes Class Prefix Examples Button a.Text Classes Class Prefix Examples StringBuilder strbld strbldInputBuffer. hashLeftover queue queueSendRequest.NET Compact Framework Delegate dele Appendix A deleFileFound.73] Queue [Comment A.74] Stack [Comment A. regkeySoftware.Add(2).67] Decoder [Comment A.k.69] Hungarian Prefixes for System.Programming the .70] ai[0] = 1. ArrayList al<type> [Comment A. regkeyVer10 [Comment A.76] Hungarian Prefixes for System.Windows.71] ArrayList ali = new ArrayList(). chkToolbar.Add(1). stackUndoCommands [Comment A. decodeHTML encode encodeDisplayBuffer.Collection Classes Class Prefix Examples <Any> [Comment a<type> int [] ai = new int[10]. encodeConvert [Comment A. BitArray bitarr bitarrDisplayFlags.Win32 Classes (Desktop Framework Only) Class Prefix Examples RegistryKey regkey regkeyRoot. // Array of integers.68] Encoder [Comment A.66] Hungarian Prefixes for System.a "Command Button" cmd cmdOk – OK button cmdReset – Button to reset form [Comment A.

tabOptionsDialog tpage tpageOptions.98] TabControl [Comment A.83] Form [Comment form A. nupdownPassengers panel panelColorScroll.89] ListView [Comment A.99] TabPage [Comment A. pboxThumbnail pbar pbarDownload.84] <form used as a dialog box> frm – temp variable dlg dlgFileOpen dlgFileSave [Comment A.80] Control [Comment A. pbarRecalc opt "opt" stands for "Option button".86] ImageList [Comment A.88] ListBox labelStatus lbox lboxFileNames lview lviewVisitors. optBlue status statusMain.85] HScrollBar formMain – main form hscroll hscrollLines. cmenuOptions ctrl ctrlParent dgrid //a "Data-Bound Grid" [Comment A. as in optRed. menuNew mitem mitemFileOpen. tpageFormat text textName [Comment A.91] MenuItem [Comment A.101] textFirst textPassword Timer [Comment timer timerPowerSave A.102] © Copyright 2002 Paul Yao & David Durant All Rights Reserved 9 of 14 9/10/2003 2:24 PM .81] DataGrid [Comment A.100] TextBox [Comment A.NET Compact Framework ContextMenu Appendix A cmenu cmenuMain. optGreen.97] StatusBar [Comment A.Programming the . ilistEdit label label1 – default label name [Comment A. mitemEditCopy nupdown nupdownMaxItems.95] ProgressBar [Comment A.82] DomainUpDown dgridPhoneList dupdown [Comment A. panelDiscountGroup pbox pboxPreview. statusHelpWindow tab tabFileDialog. hscrollElevation ilist ilistFile.93] Panel [Comment A.90] MainMenu [Comment A.92] NumericUpDown [Comment A.87] Label [Comment A.94] PictureBox [Comment A. lviewSymptoms menu menuMain.96] RadioButton [Comment A.

106] VScrollBar tvwOrgChart [Comment A. brGreen. vscrollBlue [Comment A.Drawing classes Class Prefix Examples Bitmap [Comment bmp bmpThumb. ptEnd ptf ptfName.113] Font [Comment A. fontArial g g – Standard for Graphics object icon iconHelp.112] Color [Comment A.109] Message [Comment A.121] RectangleF [Comment A. iconQuestion.119] PointF [Comment A.118] Point [Comment A.WindowsCE.NET Compact Framework ToolBar Appendix A tbar tbarFile.Programming the . vscrollGreen. imgThumb pen penRed. msgwndSearchDone msg msgIn [Comment A. ptfString rect rectStory rectf rectfPreview A.122] © Copyright 2002 Paul Yao & David Durant All Rights Reserved 10 of 14 9/10/2003 2:24 PM .105] TreeView [Comment A.120] Rectangle [Comment A.110] Hungarian Prefixes for System.103] ToolBarButton [Comment A.117] Pen [Comment A.116] Image [Comment A. tbuttonEditCopy tbar tbar tview tvwDirectory vscroll vscrollRed. tbarOptions tbutton tbuttonFileOpen.107] Hungarian Prefixes for Microsoft.Forms Classes (Windows CE only) Class Prefix Examples InputPanel sip sipMain msgwnd msgwndTextBox.104] TrackBar [Comment A. penBlack pt ptStart. colorActiveWindow font fontCurrent.114] Graphics [Comment A.111] Brush [Comment A. brYellow color colorBlack. iconMain img imgApp. bmpNext br brRed.108] MessageWindow [Comment A.115] Icon [Comment A.

143] DataViewManager [Comment A.142] DataView [Comment A.139] DataSet [Comment A.140] dset DataTable [Comment A.138] DataRowView [Comment A.137] DataRowCollection [Comment A.Programming the .131] DataException [Comment A.123] Size [Comment A.134] DataRow [Comment A.127] DataColumn [Comment A.128] dcol DataColumnChangeEventArgs e [Comment A.129] DataColumnChangeEventHandler [Comment A.136] DataRowChangeEventHandler [Comment A.124] SizeF [Comment A.Data.NET Compact Framework Region [Comment Appendix A reg regScroll sz szBackground szf szfStringSize A.145] DataViewSettingCollection [Comment A.130] DataColumnCollection [Comment A.133] DataRelationCollection [Comment A.126] ConstraintException [Comment ex A.146] DBConcurrencyException ex [Comment A.135] drow DataRowChangeEventArgs e [Comment A.132] ex DataRelation [Comment A.125] Hungarian Prefixes for System.144] DataViewSetting [Comment A. classes Class Prefix Examples ConstraintCollection [Comment A.141] dtab DataTableCollection [Comment A.147] DeletedRowInaccessibleException © Copyright 2002 Paul Yao & David Durant All Rights Reserved ex 11 of 14 9/10/2003 2:24 PM .

167] SqlCeCommand cmnd [Comment A.162] StateChangeEventHandler [Comment A.158] PropertyCollection [Comment A.159] ReadOnlyException [Comment A.156] MissingPrimaryKeyException ex [Comment A.149] EvaluateException [Comment ex A.154] InvalidConstraintException ex [Comment A.NET Compact Framework Appendix A [Comment A.169] SqlCeException ex © Copyright 2002 Paul Yao & David Durant All Rights Reserved 12 of 14 9/10/2003 2:24 PM .151] FillErrorEventHandler [Comment e A.155] InvalidExpressionException ex [Comment A.153] InRowChangingEventException ex [Comment A.165] VersionNotFoundException ex [Comment A.161] StateChangeEventArgs [Comment e A.152] ForeignKeyConstraint [Comment A.157] NoNullAllowedException ex [Comment A.164] UniqueConstraint [Comment A.Programming the .168] SqlCeDataReader drdr [Comment A.166] Hungarian Prefixes for System.150] FillErrorEventArgs [Comment e A.SqlServerCe classes Class Prefix SqlCeConnection conn Examples [Comment A.160] RowNotInTableException ex [Comment A.Data.163] SyntaxErrorException [Comment A.148] DuplicateNameException ex [Comment A.

174] Hungarian Prefixes for System.175] Hungarian Prefixes for System.177] Mutex [Comment mutex A.187] xcom © Copyright 2002 Paul Yao & David Durant All Rights Reserved 13 of 14 9/10/2003 2:24 PM .180] WaitHandle whand [Comment A.Threading classes Class Prefix AutoResetEvent autoevent Examples [Comment A.172] [Comment A.173] SqlCeDataAdapter dapt (what about sqladpt ??) SqlCeCommandBuilder cbld [Comment A.179] Timer [Comment timer A.182] xntable XmlAttribute [Comment xattr Examples A.NET Compact Framework Appendix A [Comment A.170] SqlCeError err [Comment A.Xml Classes Class Prefix NameTable [Comment A.176] ManualResetEvent manevent [Comment A.186] XmlComment [Comment A.IO classes Class Prefix FileStream fs Examples [Comment A.181] Hungarian Prefixes for System.183] XmlAttributeCollection xattcoll [Comment A.171] db Engine [Comment A.Programming the .178] Thread [Comment thread A.185] XmlCharacterData [Comment xchardata A.184] XmlCDataSection [Comment xcdatasec A.

191] xel XmlEntityReference xeref [Comment A.196] XmlNodeReader [Comment xnreader A.206] XmlWhitespace [Comment xwhite A.194] XmlNamespaceManager xnsmanager [Comment A.193] XmlNamedNodeMap [Comment xnnm A.188] XmlDocument [Comment A.200] XmlResolver [Comment A.207] © Copyright 2002 Paul Yao & David Durant All Rights Reserved 14 of 14 9/10/2003 2:24 PM .205] XmlUrlResolver [Comment xuresolver A.201] xresolver XmlSignificantWhitespace xsigwhite [Comment A.203] xtext XmlTextReader [Comment xtr A.190] XmlElement [Comment A.202] XmlText [Comment A.189] xdoc XmlDocumentFragment xdfrg [Comment A.199] XmlQualifiedName [Comment xqname A.198] XmlProcessingInstruction xpi [Comment A.Programming the .NET Compact Framework XmlDeclaration [Comment Appendix A xdecl A.197] XmlParserContext [Comment xcontext A.204] XmlTextWriter [Comment xtw A.195] XmlNodeChangedEventArgs e [Comment A.192] XmlImplementation [Comment ximp A.