无法将“System.String”类型的对象强制转换为“Student”类型。 [英] Unable to cast object of type 'System.String' to type 'Student'.

查看:94
本文介绍了无法将“System.String”类型的对象强制转换为“Student”类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿 

我在执行以下代码时遇到上述错误。请建议我该怎么做?

I am facing above error while executing following code. Please suggest what should I do?

公共班学生

{

    int id;

       字符串名称;

    public int ID

    {

       设置{id = value; }
       得到{return id; }
    }
   公共字符串名称

    {

       得到{返回名字; }
       设置{name = value; }
      

    }
    public student(int id,string name)

    {

        this.id = id;

        this.name = name;
public class Student
{
    int id;
        string name;
    public int ID
    {
        set { id = value; }
        get { return id; }
    }
    public string Name
    {
        get { return name; }
        set { name = value; }
      
    }
    public Student(int id, string name)
    {
        this.id = id;
        this.name = name;

推荐答案

显示生成此错误的行。似乎显示的代码不包含此类强制转换。您可能有一个
'学生s =(学生)some_variable',但这不起作用。


这篇关于无法将“System.String”类型的对象强制转换为“Student”类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆