ref的值传递问题。。。。
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class TuXing //父类
{
double ZhouChang; //定义周长为私有的
double MianJi; //定义面积为私有的
public double MyZhouChang //定义名为MyZhouChang的周长属性
{
get //get属性访问器
{
return ZhouChang;
}
set //set属性访问器
{
ZhouChang = value;
}
}
public double MyMianJi //定义名为MyMianJi 的面积属性
{
get //get属性访问器
{
return MianJi ;
}
set //set属性访问器
{
MianJi= value;
}
}
}
public class TuXing1 : TuXing
{
public void JuXing(ref double a,ref double b) //定义几何图形为矩形
{
MyZhouChang =(a+b); //周长
MyMianJi = a * b; //面积
}
public void SanJiaoXing(ref double A,ref double B,ref double C) //定义几何图形为三角形
{
double s = (A + B + C) / 2;
MyZhouChang = A + B + C; //周长
MyMianJi = (Math.Sqrt(s * (s - A) * (s - B) * (s - C))); //面积
}
public void Yuan(ref double R) //定义几何图形为圆
{
MyZhouChang = 2 * (Math.PI) * R; //周长
MyMianJi =(Math .PI )*(Math.Sqrt(R)); //面积
}
}
class Program
{
static void Main(string[] args)
{
double a;
double b;
double c;
double MianJi;
double ZhouChang;
TuXing1 TX=new TuXing1 ();
MianJi = TX.MyMianJi ;
ZhouChang = TX.MyZhouChang;
Random rand = new Random();
a = rand.Next(1, 20);
b = rand.Next(1, 20);
c = rand.Next(1, 20);
Console.WriteLine("a=" + a + " " + "b=" + b + " " + "c=" + c + " ");
TX.JuXing( ref a, ref b);
Console.Write("矩形的周长及面积分别为:");
Console.WriteLine(ZhouChang + " " + MianJi);
TX.Yuan(ref a);
Console.Write("圆的周长及面积分别为:");
Console.WriteLine(ZhouChang + " " + MianJi);
if ((a - b < c && a + b > c) && (a - c < b && a + c > b) && (b - c < a && b + c > a))
{
TX.SanJiaoXing(ref a,ref b,ref c);
}
Console.Write("三角形的周长及面积分别为:");
Console.WriteLine(ZhouChang + " " + MianJi);
}
}
}
请问哪里错了????输出的结果都为0。,路过的朋友帮帮忙啊。。。。