Can Someone Explain the Following Code to Me

Can someone explain the following code to me?

It's string interpolation. "#{email} (#{admin? ? "Admin" : "User"})" is equivalent to

email.to_s + " (" + (admin? ? "Admin" : "User") + ")"

that is

email.to_s + " (" + if admin? then "Admin" else "User" end + ")"

As a result of being enclosed in quotes, in this context Admin and User are used as strings and not as constants.

Can Someone Explain This Code To Me?

It's basically creating a delegate from the native code for multiplication, and then invoking it. The byte arrays are the raw instructions, which are then pinned in memory, set to be executable, and then Marshal.GetDelegateForFunctionPointer is creating the delegate itself.

The conditional operator is to use different native code for x86 and x64. I suspect this would fail when running on Mono on an ARM processor, for example :)



Related Topics



Leave a reply



Submit