Q:

Equivalent of func_get_arg in C#?

Is there an equivalent to func_get_arg (php) in C#?

func_get_arg ( int $arg_num ):
Gets the specified argument from a user-defined function's argument list.
This function may be used in conjunction with func_get_args() and func_num_args() to allow user-defined functions to accept variable-length argument lists.

It basically means the index can be used to get the argument value...
Thanks

A:

C# is statically typed, so function signatures matter. You can't just call a method with any number of arguments, which really means there is no need for func_get_arg.
That said, you can get pretty close if you have a method such as this one:
void MyMethod(params object[] args)
{
    var indexOfArgument = 42; // or whatever
    var valueOfArgument = args[indexOfArgument]; // should also check array bounds
}

Of course if all your arguments are typed as System.Object there's not much you can do with them, but from a syntactic viewpoint it's close (plus, you could also have a method that accepts params T[] args for any type T).

