简体   繁体   English

将类作为变量C#传递

[英]Passing a Class as Variable C#

I need some help, hope it is doable. 我需要一些帮助,希望它是可行的。

I would like to pass a Class as a variable in C#. 我想将Class作为变量传递给C#。

This is my code so you can see what I am trying to do: 这是我的代码,因此您可以看到我要执行的操作:

object shClass;
switch ((cbxType.SelectedItem as ComboBoxItem).Value)
{
    case "articles":
            shClass = ArticlesClass;
            break;
    case "topics":
            shClass = TopicsClass;
            break;
}
serializer.Deserialize<shClass>(response);

This code does not work, and this just to give you an idea what I need. 这段代码不起作用,只是为了让您知道我需要什么。 Is this possible? 这可能吗?

I hope you can help me out. 我希望你能帮助我。 Thank you. 谢谢。

Why you need to put it outside the switch?? 为什么需要将其放在交换机外部? You can try putting it inside instead 您可以尝试将其放在里面

switch ((cbxType.SelectedItem as ComboBoxItem).Value)
{
    case "articles":
            serializer.Deserialize<ArticlesClass>(response);
            break;
    case "topics":
            serializer.Deserialize<TopicsClass>(response);
            break;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM