Variables
Also known as Identifiers.
A variable is just a named storage location in memory. At the top of all your modules you should have "Option Explicit" to force explicit declaration.
Variables are case sensitive in C#.
Variables that are not defined explicitly have the "Variant" data type assigned to them by default.
Variables can accommodate a wide variety of data types from simple boolean values to extremely large 20 digit numbers.
In C# assigning values to variables and comparing values are treated as two very different operations.
Because of this they have different symbols
= - for assignment
== - for comparison
In VB this is the same symbol (=).
Prefix private variables with an underscore "_"
Use Pascal casing for public variables
Use Hungarian notation for private or local variables
Always try and declare your local variables at the very top of the method and not amongst lines of code
Do not use language specific type names. For example use Int16 instead of Short
Inside or Outside
Do you declare the variables inside or outside the try block.
public bool DoSomething(
string sPassedIn)
{
Excel.Worksheet oWorksheet;
float myNumber;
try
{
Discards
Discards are placeholder variables that are intentionally unused in application code.
Discards are equivalent to unassigned variables; they don't have a value.
A discard communicates intent to the compiler and others that read your code:
You intended to ignore the result of an expression.
You may want to ignore the result of an expression, one or more members of a tuple expression, an out parameter to a method, or the target of a pattern matching expression.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext