C# Compatibility
Mapping table from C# / .NET constructs to sharp-runtime C++ equivalents.
Primitive Types
| C# type | C++ / sharp-runtime | Notes |
sbyte | SharpRuntime::sbytecs / int8_t | |
byte | SharpRuntime::bytecs / uint8_t | Most common in I/O |
short | SharpRuntime::shortcs / int16_t | |
ushort | SharpRuntime::ushortcs / uint16_t | |
int | SharpRuntime::intcs / int32_t | Use in public APIs |
uint | SharpRuntime::uintcs / uint32_t | |
long | SharpRuntime::longcs / int64_t | |
ulong | SharpRuntime::ulongcs / uint64_t | |
float | float | Native C++ |
double | double | Native C++ |
bool | bool | Native C++ |
char | SharpRuntime::charcs / char16_t | UTF-16 code unit |
string | std::string | UTF-8 by convention |
Object Model
| C# construct | C++ / sharp-runtime equivalent |
object / Object | System::Object |
obj.GetType().Name | obj.GetTypeName() |
obj.ToString() | obj.ToString() |
obj.Equals(other) | obj.Equals(other) |
Object.ReferenceEquals(a,b) | System::Object::ReferenceEquals(a,b) |
obj.GetHashCode() | obj.GetHashCode() |
null | nullptr |
new MyClass() | new MyClass() or std::make_shared<MyClass>() |
Collections
| C# type | C++ / sharp-runtime | Notes |
T[] | std::vector<T> | Standard C++ |
List<T> | System::Collections::Generic::List<T> | Wraps std::vector |
Dictionary<K,V> | System::Collections::Generic::Dictionary<K,V> | Wraps std::unordered_map |
HashSet<T> | System::Collections::Generic::HashSet<T> | Wraps std::unordered_set |
Queue<T> | System::Collections::Generic::Queue<T> | |
Stack<T> | System::Collections::Generic::Stack<T> | |
SortedDictionary<K,V> | System::Collections::Generic::SortedDictionary<K,V> | Wraps std::map |
LinkedList<T> | System::Collections::Generic::LinkedList<T> | |
ImmutableArray<T> | System::Collections::Immutable::ImmutableArray<T> | shared_ptr<const vector<T>> |
String Operations
| C# code | C++ / sharp-runtime equivalent |
string.Empty | "" or std::string{} |
String.IsNullOrEmpty(s) | System::String::IsNullOrEmpty(s) |
s.Split(',') | System::String::Split(s, ',') |
s.StartsWith("x") | System::String::StartsWith(s, "x") |
String.Format("{0}", n) | System::String::Format("{0}", n) |
s.Length | s.size() or s.length() |
s.Substring(i, n) | s.substr(i, n) |
s.ToLower() | No direct equivalent; use std algorithms |
s.Trim() | No direct equivalent; implement manually |
s.Contains("x") | s.find("x") != std::string::npos |
new StringBuilder() | System::Text::StringBuilder sb; |
sb.Append(x) | sb.Append(x) |
sb.ToString() | sb.ToString() |
Exceptions
| C# code | C++ / sharp-runtime |
throw new ArgumentException("msg") | throw System::ArgumentException("msg") |
catch (Exception e) | catch (const System::Exception& e) |
e.Message | e.getMessageProperty() |
e.ToString() | e.what() |
Delegates and Events
| C# code | C++ / sharp-runtime |
Action action = () => { }; | System::Action action = []{ }; |
Action<T> a = t => { }; | System::ActionT<T> a = [](T t){ }; |
Func<int> f = () => 42; | System::Func<int> f = []{ return 42; }; |
Predicate<T> p = x => x > 0; | System::Predicate<T> p = [](T x){ return x>0; }; |
event EventHandler<T> E; | System::EventHandler<T> E; |
E += handler; | E += handler; |
E?.Invoke(sender, args) | if (!E.Empty()) E.Raise(sender, args); |
Properties
| C# code | C++ / sharp-runtime |
public int Width { get; set; } | DDATA(int, Width) macro (with getWidthProperty() / setWidthProperty()) |
public int Width { get; } | DGETTER(int, Width) macro (read-only) |
obj.Width | obj.getWidthProperty() |
obj.Width = 5 | obj.setWidthProperty(5) |
Nullable Types
| C# code | C++ / sharp-runtime |
int? x = null; | System::Nullable<int> x; |
int? x = 42; | System::Nullable<int> x = 42; |
x.HasValue | x.getHasValueProperty() |
x.Value | x.getValueProperty() |
x ?? 0 | x.GetValueOrDefault(0) |
Not Supported
⚠ Features not available in sharp-runtime
- Garbage collection — use RAII and smart pointers
- LINQ — use
std::ranges
- async/await — no compiler support in C++
- Full reflection (member enumeration, dynamic invocation)
- Activator.CreateInstance()
- Dynamic types (
dynamic)
- Checked arithmetic (except via explicit checks)
- Operator overloading on delegates (only
operator+= on EventHandler)
- Extension methods (no language support)
- Iterator blocks (
yield return)