Skip to end of metadata
Go to start of metadata

This task involved demonstrating some capabilities of functions in C#.

How do you define the return type of a function? Must all functions have a return value or type?

You define it right before the function name, as usual. They must have a return type, or else use void.

Can you overload functions in your language? If so, what are the rules for differentiating overloaded functions?

You can overload functions with number of parameters, parameter types, and order of parameters.

Can you create functions with an unknown number of arguments? How do you access those arguments?

Yes. You just need to declare a params list as an argument, which is where however many of them are stored. See the example below.

Can you dynamically create functions? If so, how?

Technically, using DLINQ or making a DynamicMethod, you can, but it will be very challenging and/or time consuming.

Can you override functions with a new definition?

Yes. In C#, you must put :baseFunction after declaring the new class, and declare the original as a virtual method, while the other is an override method. Refer to this code:

What mechanism exists for publishing the existence of a function to other functions or compilable units (e.g. files)?

The files in the project all share the same namespace, which means they can all "see" each other.


  • No labels