Summary#
A C# file you paste carries spellings that name nothing new — a namespace prefix, a BCL type name, a #region. Each
compiles here with the meaning C# gives it:
| Written | Means | Why |
|---|---|---|
System.Math.Max(2, 3), System.Text.StringBuilder | Math.Max(2, 3), StringBuilder | those types are Osy#'s own and always in scope, as with using System; |
global::System.Math.Abs(-3) | Math.Abs(-3) | every name already resolves from the global namespace |
Int32, Int64, String, Decimal, Double, Boolean, Char, Byte | int, long, string, decimal, double, bool, char, byte | the keyword is C#'s alias for exactly that type |
#region / #endregion, #pragma, #nullable, #warning | nothing | they fold an outline or tune C#'s own warnings |
#define X … #if X … #endif | the branch whose condition holds | C#'s conditional compilation, over the file's symbols |
global using X; | using X; in every file | C# 10's project-wide import |
Signature#
int Bigger(int a, int b) => System.Math.Max(a, b); // System.Math IS Math
Int32 Count; // Int32 IS int
#region Helpers … #endregion // inert
#if DEBUG … #elif TRACE … #else … #endif // C#'s conditional compilation
global using Shop; // an import every file seesDescription#
Which System. names compile?#
A name qualified by a .NET namespace whose types Osy# provides — System, System.Collections.Generic, System.Linq,
System.Text, System.Text.Json, System.Text.RegularExpressions, System.Threading.Tasks, System.Net — is the
type itself. global:: in front changes nothing either.
int Bigger(int a, int b) { return System.Math.Max(a, b); }
int Distance(int a) { return global::System.Math.Abs(a); }
string Joined() {
var sb = new System.Text.StringBuilder();
var parts = new System.Collections.Generic.List<string> { "a", "b" };
foreach (var p in parts) { sb.Append(p); }
return sb.ToString() + System.String.Empty;
}A namespace Osy# does not provide keeps its qualification and is refused by that namespace — System.IO.Path answers
"System.IO.Path is from a .NET namespace Osy# does not provide", and System.Threading.* adds that there are no
threads to lock ([[function-csharp-exclusions#threads]]).
What do Int32 and String mean here?#
The type their keyword names. Int32 is int in a signature, a local, a property, a generic argument, a cast and as
the receiver of a static (Int32.Parse):
entity Rate { Decimal Value; Int32 Count; Boolean Live; }
Int64 Scaled(Int32 x) { return (Int64)x * Int32.Parse("3"); }
decimal Sum() {
Decimal d = 1.5m; Int32 i = 2; String s = "ab"; Boolean b = true;
return d + i + s.Length + (b ? 1 : 0); // 6.5, as in C#
}Object is not on the list: object is a type keyword Osy# leaves out, and the refusal says so by name.
Which preprocessor directives work?#
All of C#'s, at the start of a line. #region/#endregion, #pragma (warning and checksum alike), #nullable and
#warning change nothing about what the program means, so they are accepted and ignored. #error text stops the
compile with its text. #line is refused: it renumbers the file for a code generator, and every diagnostic here points
at the source as written. A # line that is no directive — # a comment — is refused by name; a comment is //.
#region Helpers
#pragma warning disable CS0168
int One() { return 1; }
#pragma warning restore CS0168
#endregionWhat does #if test?#
The symbols this FILE defines with #define (and removes with #undef), written before its first line of code, as C#
requires — combined with !, &&, ||, ==, !=, parentheses, true and false — and the platform's feature
symbols, which every file has (C#'s NET8_0_OR_GREATER): OSY_ACTOR_PRINCIPAL_IDS on a platform with
Actor.PrincipalIds(). A platform older than a symbol does not define it, so a kit that must still compile there keeps
the old code in the #else. A branch that is not taken is not read at all, so it need not be valid Osy#:
#define FAST
#if FAST && !SLOW
int Mode() { return 1; }
#elif SLOW
int Mode() { return 2; }
#else
anything at all — this branch is never read
#endifWhat does global using do?#
The same import as using X;, in force in every file of the app instead of only its own — C# 10's meaning. For a
System.* namespace it changes nothing (those types are always in scope); for one of the app's own namespaces or a
capability, a file with no using of its own sees it.
global using System.Text;
string Greeting() { return new StringBuilder().Append("g").ToString(); }global using static T; and a global using A = T; alias are refused by name: those two forms hold for the file they
are written in, so write them without global in each file that needs them.
See also#
- The C# Osy# leaves out — and why — what Osy# leaves out on purpose, each refused by name with its reason
- use —
useandusing, and whichusing System.…lines compile unchanged - function — what a function is