看代码:
using System;
using System.Windows.Forms;class yuan
{
 public static void Main()
{
 string strfs=Console.ReadLine();
 //string Msg=""
int intfs=Int32.Parse(strfs);
 //intfs=(intfs > 60) ? Msg="及格":Msg="不及格";
 intfs=(intfs > 60) ? intfs+=1:intfs-=1;
 Console.WriteLine(intfs);
}
}
我用记事本书写完后在命令行编译器下编译该语句,正常通过;
但是我如果用//中的Msg来就会出现error cs0029:无法将类型"string",隐式转换为"int";
为何出此错误,请明示!谢谢!

解决方案 »

  1.   

    to //intfs=(intfs > 60) ? Msg="及格":Msg="不及格";你不能把一个“及格”类似的字符串付给一个整型
      

  2.   

    string strfs=(int)Console.ReadLine();
      

  3.   

    //intfs=(intfs > 60) ? Msg="及格":Msg="不及格";展开:if ( intfs > 60 )
      intfs = Msg = "及格";
    else
      intfs = Msg = "不及格";
    赋值表达式也是表达式,是表达式就有值,如果非要用?:可以改成这样:intfs = (intfs > 60) ? (Msg="及格").Length * 0 + intfs : (Msg="不及格").Length * 0 + intfs;
      

  4.   

    intfs=(intfs > 60) ? Msg="及格":Msg="不及格";
    改成
    if(intfs > 60)
    Msg="及格";
    else
    Msg="不及格";那种写法相当于
    intfs=Msg="及格"
    intfs=Msg="不及格"// 你说说能对吗?
      

  5.   

    intfs=(intfs > 60) ? Msg="及格":Msg="不及格";intfs=(Int32.Parse(intfs) > 60) ? Msg="及格":Msg="不及格";
      

  6.   

    这样对了,(intfs > 60) ? Msg="及格":Msg="不及格";
      

  7.   

    这样
    (intfs > 60) ? Msg="及格":Msg="不及格";
      

  8.   

    LZ,上面的程序能运行吗?程序集都没有WIINDWOS.FORM
    e:\Visual Studio\ConsoleApplication1\ConsoleApplication1\Class1.cs(2): 类型或命名空间名称“Windows”在类或命名空间“System”中不存在(是否缺少程序集引用?)
    ------------
    怎么运行的?你只有把using System.Windows.Forms;去掉才有可能运行-------------------------------------
    intfs=(intfs > 60) ? Msg="及格":Msg="不及格";
    ------------------
    intfs是int型,Msg是字符串型,当然有错了!
      

  9.   

    错了,只需改成:
    Msg = (intfs > 60) ? "及格":"不及格";
    被楼主绕糊涂了……