C# Compatibility

Mapping table from C# / .NET constructs to sharp-runtime C++ equivalents.

Primitive Types

C# typeC++ / sharp-runtimeNotes
sbyteSharpRuntime::sbytecs / int8_t
byteSharpRuntime::bytecs / uint8_tMost common in I/O
shortSharpRuntime::shortcs / int16_t
ushortSharpRuntime::ushortcs / uint16_t
intSharpRuntime::intcs / int32_tUse in public APIs
uintSharpRuntime::uintcs / uint32_t
longSharpRuntime::longcs / int64_t
ulongSharpRuntime::ulongcs / uint64_t
floatfloatNative C++
doubledoubleNative C++
boolboolNative C++
charSharpRuntime::charcs / char16_tUTF-16 code unit
stringstd::stringUTF-8 by convention

Object Model

C# constructC++ / sharp-runtime equivalent
object / ObjectSystem::Object
obj.GetType().Nameobj.GetTypeName()
obj.ToString()obj.ToString()
obj.Equals(other)obj.Equals(other)
Object.ReferenceEquals(a,b)System::Object::ReferenceEquals(a,b)
obj.GetHashCode()obj.GetHashCode()
nullnullptr
new MyClass()new MyClass() or std::make_shared<MyClass>()

Collections

C# typeC++ / sharp-runtimeNotes
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# codeC++ / 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.Lengths.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# codeC++ / sharp-runtime
throw new ArgumentException("msg")throw System::ArgumentException("msg")
catch (Exception e)catch (const System::Exception& e)
e.Messagee.getMessageProperty()
e.ToString()e.what()

Delegates and Events

C# codeC++ / 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# codeC++ / 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.Widthobj.getWidthProperty()
obj.Width = 5obj.setWidthProperty(5)

Nullable Types

C# codeC++ / sharp-runtime
int? x = null;System::Nullable<int> x;
int? x = 42;System::Nullable<int> x = 42;
x.HasValuex.getHasValueProperty()
x.Valuex.getValueProperty()
x ?? 0x.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)