0

我在F2008

module mod_Blood
use mod_liquid
implicit none
type, public :: typ_BloodComponents
    character(len=5) :: name
    real(DP):: salt
    real(DP):: RBC
end type typ_BloodComponents

type, public :: typ_BloodWork
    real(DP) :: DrugConc
    real(DP) :: Dilution
    real(DP) :: volume  
    type(typ_BloodComponents) :: vein, artery

    contains
          procedure :: SetParameters => blood_SetParameters
          procedure :: BloodProteinParams  => blood_BloodProteinParams   
end type typ_BloodWork
end mod_Blood

我知道静脉和动脉都有变量静脉%名称,静脉%盐,静脉%RBC和动脉%名称,动脉%盐和动脉%RBC。

如何将其转移到 C#?模块是命名空间吗?FORTRAN“类型”是 C# 中的一个类吗?

如果我这样做是否有意义:

class BloodComponents
{
string name;
double salt;
double RBC;
}

class BloodWork
{
    double drugConc
    double dil
    double volume

    class Vein : BloodComponents
    {}
    class Artery : BloodComponents
    {}

    void SetParameters()
    {...}
    void BloodComponentParameter()
    {...}
}

还是我对 FORTRAN 的解释有误?

4

1 回答 1

0

我认为这就是你想要的:

namespace Blood
{
    public struct BloodComponents
    {
        public string name;
        public double salt, RBC;
    }

    public struct BloodWork
    {
        public double drugConc, dilution, volume;
        public BloodComponents vein, artery;

        public void SetParameters()
        {
        }
        public void BloodProteintParams()
        {
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var work=new BloodWork()
            {
                drugConc=0.1,
                dilution=0.2,
                volume=0.3,
                vein=new BloodComponents() { name="A", RBC=0.2, salt=0.6 },
                artery=new BloodComponents() { name="B", RBC=0.5, salt=0.9 }
            };
        }
    }
}

一切都是struct如此,因此仅复制值。如果您想BloodWork在多个地方引用例如同一时刻,那么您需要将类型更改为class.

于 2013-05-24T16:49:04.260 回答