public SqlConnection getcon(){
...}
public void getcom(string M_str_sqlstr){
SqlConnection sqlcon=this.getcon();
...}
我调试过了红色字体为什么不能等价于SqlConnection sqlcon=new SqlConnection(this.getcon());?
它等价于SqlConnection sqlcon=(SqlConnection)this.getcon();这句不也是创建一个SqlConnection类并赋值吗?初学者概念不清楚,请高手指教。

解决方案 »

  1.   

    SqlConnection sqlcon=new SqlConnection(this.getcon());其中:this.getcon()返回的是什么? 是一个SqlConnection .new SqlConnection(); 里面的参数应该是string形的吧。如果有SqlConnection类型的参数重载,那你哪个就正确。其实直接:SqlConnection sqlcon= this.getcon();就可以了。不需要强制转化。(你的错误应该是类型不匹配)