object s;
s = "abc";
int n = ((string)s).Length;
Is there any way of avoiding having to use the cast in the 3rd line?
edit: “string” and “length” are just examples and could be different.
edit: Further clarified regarding var and dynamic by breaking up the first line to be more like my requirements.
1 Answer