Re: [问题] 请教 null 的用法

楼主: tooto1985 ( )   2014-01-08 09:04:48
※ 引述《netsm (小黑)》之铭言:
: 请教各位高手,下面的写法是什么意思?
: 谢谢!
: if (Math.Abs(t - 0.3) < dt / 2)
: {
: write("..\\(2D)u" + filename + ".plt", u);
: write("..\\(2D)uexact_" + filename + ".plt", null);
: }
: //////
: public static void write(string fname, fun ux)
: {
: FileStream fs = new FileStream(fname, FileMode.Create);
: StreamWriter sw = new StreamWriter(fs, Encoding.Default);
: sw.WriteLine("VARIABLES=x, y, u1");
: sw.WriteLine("ZONE T=\"dx={0}, dy={1}\", I={2}, J={3}, F=POINT",
: dx, dy, Ni/2, Nj);
: for (double y = 0; y <= MaxY; y += dy)
: for (double x = 0; x <= MaxX; x += dx)
: {
: double uk=(ux==null)? (exact(t,x,y)): ux.f1(0, x, y, 0, 0, 0);
: sw.WriteLine("{0},{1},{2}", x, y, uk);
: }
: sw.Close();
: }
: 请教: double uk=(ux==null)? (exact(t,x,y)): ux.f1(0, x, y, 0, 0, 0);
: 是什么样的逻辑?
这是三元运算子: 条件 ? true执行 : false执行
uk=(ux==null) 的意思是先判断 (ux==null) 其结果指派给 uk
所以 uk 是个布林值 , 接下来利用三元运算子
执行 exact(t,x,y) 或 ux.f1(0,x,y,0,0,0)
最后结果会是 double
: 我读出来的档案 write("..\\(2D)uexact_" + filename + ".plt", null);
: 只有时间t有值,而x,y皆为零,是否与 null 有关?
我只能说不确定
你必须去看 exact 或 ux.f1 方法里面是怎么定义的
楼主: tooto1985 ( )   2014-01-08 09:06:00
补充:这边都没看到uk,dx,dy宣告,可能在外层就先宣告好了

Links booklink

Contact Us: admin [ a t ] ucptt.com