Search

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, July 18, 2023

C# commonly used variable types & Naming standards

 In C#, there are different types of variables based on their data types and storage requirements. Here are some commonly used variable types:



Value Types:

  • `int`: Represents whole numbers.
  • `double`: Represents floating-point numbers with double precision.
  • `bool`: Represents boolean values (true or false).
  • `char`: Represents single Unicode characters.
  • `enum`: Represents a set of named values.
  • `struct`: Represents a lightweight data structure.


Reference Types:

  • `string`: Represents a sequence of characters.
  • `object`: Represents a base type for all other types.
  • `class`: Represents a reference type with complex data structures.
  • `interface`: Represents a contract for classes to implement.


Other Types:

  • `var`: Represents an implicitly typed variable whose type is inferred by the compiler.
  • `dynamic`: Represents a type that defers type checking until runtime.


Naming standards for variables in C#:

  • Use meaningful and descriptive names: Choose names that accurately reflect the purpose or content of the variable. Avoid generic or ambiguous names.
  • Use camelCase: Start variable names with a lowercase letter and use camelCase for multi-word names. For example, `firstName`, `studentAge`, `employeeCount`.
  • Avoid Hungarian notation: Avoid using prefixes or encoding the variable type into its name, as it is not necessary in C#. For example, avoid prefixes like `str` for strings or `i` for integers.
  • Be consistent: Maintain consistency in naming conventions throughout your codebase. Use similar naming styles for variables of the same type or purpose.
  • Use proper casing for acronyms and abbreviations: Use PascalCase for acronyms and abbreviations that consist of two or more characters. For example, `XMLHttpRequest`, `PDFDocument`.


No comments:

Post a Comment