N
N
NooBick2020-10-06 22:37:29
C++ / C#
NooBick, 2020-10-06 22:37:29

C#, what's wrong?

5f7cc73a83a81426822448.png
What's wrong? Everything works, but as I add [] immediately an error.
5f7cc76e536c5612001536.png

How to do it right?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2020-10-06
@NooBick

And what do you store in o? Is it indexed? If it is indexed, then set this type in forich instead of object.
And yes - redo the question so that there are no screenshots!

V
Vasily Bannikov, 2020-10-07
@vabka

You have to specify the element type Object in the foric, and Object does not have this[string] indexer (your cap).
How to solve:
a. Indicate the correct type (xs which one, it's not clear from the screen - throw the full code on gist or pastebin, or right here)
b. Through reflection a la

var type = listen.GetType();
var prop = type.GetProperty("currency");
var value = prop.GetValue(listen);
but I'm not sure if that's what's needed here.
d. Write var instead of Object
e. Write dynamic and call listen.currency or listen["currency"]
f. Write a complete class?
PS:
Why do if you can or ? Task.Delay(100).GetAwaiter().GetResult();Thread.Sleep(100);await Task.Delay(100);

C
cicatrix, 2020-10-07
@cicatrix

Natively cast listen, object does not support indexing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question