Browse by Tags

Tagged Content List
  • Blog Post: Ref returns and ref locals

    "Ref returns" are the subject of another great question from StackOverflow that I thought I might share with a larger audience. Ever since C# 1.0 you've been able to create an "alias" to a variable by passing a "ref to a variable" to certain methods: static void M(ref int x) { x = 123; } ... int...
  • Blog Post: References and Pointers, Part Two

    Here's a handy type I whipped up when I was translating some complex pointer-manipulation code from C to C#. It lets you make a safe "managed pointer" to the interior of an array. You get all the operations you can do on an unmanaged pointer: you can dereference it as an offset into an array, do addition...
  • Blog Post: References and Pointers, Part One

    Writing code in C# is really all about the programmatic manipulation of values . A value is either of a value type, like an integer or a decimal, or it's a reference to an instance of a reference type, like a string or an exception. Values you manipulate always have a storage location that stores the...
  • Blog Post: Why do ref and out parameters not allow type variation?

    Here's a good question from StackOverflow : If you have a method that takes an "X" then you have to pass an expression of type X or something convertible to X . Say, an expression of a type derived from X. But if you have a method that takes a "ref X", you have to pass a ref to a variable of type...
Page 1 of 1 (4 items)