问题描述
我在F2008中使用mod_liquid
隐式无
类型
模块mod_Blood
,public :: typ_BloodComponents
character(len = 5):: name
real(DP):: salt
real(DP):: RBC
结束类型typ_BloodComponents
type,public :: typ_BloodWork
real(DP):: DrugConc
real(DP)::稀释
real(DP):: volume
type( typ_BloodComponents):: vein,artery
包含
procedure :: SetParameters => blood_SetParameters
procedure :: BloodProteinParams => blood_BloodProteinParams
end type typ_BloodWork
end mod_Blood
我知道静脉和动脉都有变量静脉%名称,静脉%盐,静脉%红细胞和动脉%名称,动脉%盐和动脉%RBC。
我怎样才能将这个转换为C#?模块是一个命名空间吗?这是一个FORTRAN类型在C#中的类?
如果我做了类似的事情,它是有道理的:
class BloodComponents
{
string name;
复盐;
双RBC;
}
类血液
{
double drugConc
double dil
双倍数量
类静脉:BloodComponents
{}
class Artery:BloodComponents
{}
void SetParameters()
{...}
void BloodComponentParameter()
{...}
}
或者我解释了FORTRAN错误?
我想这就是你想要的:
namespace Blood
{
public struct BloodComponents
{
public string name;
公共复盐,RBC;
}
公共结构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,
稀释= 0.2,
体积= 0.3,
静脉=新BloodComponents(){名称=A,RBC = 0.2,盐= 0.6},
blood = bloodComponents(){name =B,RBC = 0.5,salt = 0.9}
};
$ / code $ / pre
一切都是一个 struct
,所以值只被复制。如果您想要在多个地方引用 BloodWork
的相同时刻,那么您需要将类型更改为 class
。
I have in 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
I know that vein and artery both have variables vein%name, vein%salt, vein%RBC and artery%name, artery%salt and artery%RBC.
How can I transfer this over to C#? Is a module a namespace? And is a FORTRAN "type" a class in C#?
Would it make sense if I did something like:
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()
{...}
}
Or have I interpreted the FORTRAN wrong?
解决方案 I think this is what you want:
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 }
};
}
}
}
Everything is a struct
so values are copied only. If you want to reference the same instant of BloodWork
for example in multiple places then you need to change the type to class
.
这篇关于从FORTRAN到C#的类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!