Today is my third day of learning programming. As a nurse who switched careers to learn programming, I was pleasantly surprised to find that the logical thinking of programming has many similarities with the clinical thinking in nursing work. In nursing work, we need rigorous evaluation, precise judgment and standardized operating procedures. These qualities are equally important in the programming world. Today's study gave me a deeper understanding of the basics of C#.
1. Type conversion (Convert)
In medical information systems, data type conversion is a very common operation. Just as we need uniform units in clinical work (such as converting pounds to kilograms), we often need to convert between different data types in programming.
If the two types are compatible, we can use automatic type conversion or forced type conversion. But for incompatible types (such as string and int, or string and double), we need to use Convert as a conversion factory to convert.
It is important to note that when using Convert for type conversion, the data must be "visible." Just as the data we enter in a hospital must be accurate, the data at the time of conversion must also be reasonable.
// 将体温数据从字符串转换为浮点数
string temperature = "37.2";
double tempValue = Convert.ToDouble(temperature);
// 将血压值从字符串转换为整数
string systolicPressure = "120";
int systolic = Convert.ToInt32(systolicPressure);
// 将病床号从字符串转换为整数
string bedNumber = "205";
int bedNo = Convert.ToInt32(bedNumber);
Second, arithmetic operators: ++, --
In C#, the operators ++ and--may seem simple, but they require special attention when used in practice. They are divided into two forms: preposition (n) and postposition (n), with subtle differences in effects.
Just as in nursing work, the order in which patients are given medicines affects the treatment effect, the position of these two forms in the expression will also affect the final calculation result:
// 统计病房巡查次数
int roundCount = 10;
int result1 = 5 + ++roundCount; // 前++:先将roundCount加1,再参与计算
// roundCount变为11,result1为16
int visitCount = 10;
int result2 = 5 + visitCount++; // 后++:先用原值计算,再将visitCount加1
// visitCount变为11,result2为15
// 在药品库存管理中
int medicineStock = 100;
int currentStock = --medicineStock; // 先减1再赋值
// medicineStock和currentStock都是99
int supplyStock = 100;
int oldStock = supplyStock--; // 先赋值再减1
// supplyStock变为99,但oldStock仍为100
3. Relational operators and boolean types
Relational operators (>,<,>=,<=,==,!=) It is widely used in medical practice. They are like the various judgments we make in clinical work: Is your body temperature normal? Does blood pressure exceed the standard? Is the heart rate within a safe range?
The bool type has only two values in C#: true and false. This is very similar to many of our clinical judgments, such as whether the patient has specific symptoms and whether he needs special care.
// 体温监测
double bodyTemp = 37.5;
bool hasFever = bodyTemp >= 37.3; // 判断是否发烧
// 心率监测
int heartRate = 75;
bool isNormal = heartRate >= 60 && heartRate <= 100; // 判断心率是否正常
// 血压监测
int systolic = 135;
int diastolic = 85;
bool isHypertension = systolic > 140 || diastolic > 90;
4. Logical operators
Logical operators (&,||、!)Play an important role in medical diagnosis and nursing decisions. They are like the thought processes we use when conducting a clinical evaluation:
- &&(Logical AND): All conditions must be met, just like when judging whether a patient is suitable for discharge, multiple indicators need to be normal.
- ||(Logical OR): As long as any condition is met, just like when judging whether emergency treatment is needed, any risk indicator requires immediate attention.
- ! (Logical NO): The results are reversed, like when we judge whether a patient is not suitable for a certain treatment.
// 1. 逻辑与(&&)示例:判断病人是否可以手术
double bodyTemp = 36.8;
int heartRate = 72;
int bloodSugar = 5;
bool canSurgery = (bodyTemp <= 37.2) && (heartRate < 100) && (bloodSugar < 6.1);
Console.WriteLine("是否可以手术: " + canSurgery);
// 2. 逻辑或(||)示例:判断是否需要紧急医疗干预
int systolic = 180; // 收缩压
int diastolic = 95; // 舒张压
double oxygenLevel = 92; // 血氧水平
bool needEmergencyCare = (systolic >= 180) || (diastolic >= 120) || (oxygenLevel < 93);
Console.WriteLine("是否需要紧急处理: " + needEmergencyCare);
// 3. 逻辑非(!)示例:判断患者是否不适合某项检查
bool hasAllergy = true; // 是否有过敏史
bool isPregnant = false; // 是否怀孕
bool canDoCtScan = !(hasAllergy || isPregnant); // 不适合CT检查的情况取反
Console.WriteLine("是否可以进行CT检查: " + canDoCtScan);
// 组合使用示例:判断是否需要转入ICU
int respiratoryRate = 25; // 呼吸频率
bool hasShock = true; // 是否休克
bool isStable = false; // 是否病情稳定
bool transferToICU = (respiratoryRate > 30 || hasShock) && !isStable;
Console.WriteLine("是否需要转入ICU: " + transferToICU);
Through these examples, we can see the practical application of logical operators in medical decision-making. The combined use of these operators can help us build complex judgment conditions, just as we need to consider multiple factors to make decisions in clinical work.
It is worth noting that:
- When judging by the & operator, if the first condition is false, it will not continue to judge subsequent conditions
- ||When judging by the operator, if the first condition is true, it will not continue to judge subsequent conditions
- ! Operator can be combined with other logical operators to change the result of the entire determination
5. Compound assignment operator
Composite assignment operators (+=, -=, *=,/=, %=) can make our code more concise. These operators are particularly useful in medical data processing:
// 药品库存管理
int medicineStock = 100;
medicineStock += 50; // 进货50件,等同于 medicineStock = medicineStock + 50
Console.WriteLine($"当前库存: {medicineStock}"); // 输出150
// 计算累计用药量(单位:ml)
double totalDosage = 500;
totalDosage -= 50; // 使用50ml,等同于 totalDosage = totalDosage - 50
Console.WriteLine($"剩余药量: {totalDosage}"); // 输出450
// 计算病房床位使用率
int totalBeds = 100;
int occupiedBeds = 80;
double occupancyRate = 0.8;
occupancyRate *= 100; // 转换为百分比,等同于 occupancyRate = occupancyRate * 100
Console.WriteLine($"床位使用率: {occupancyRate}%"); // 输出80%
// 计算每个护士的负责病人数
int patientCount = 45;
int nurseCount = 6;
double patientsPerNurse = 45;
patientsPerNurse /= 6; // 等同于 patientsPerNurse = patientsPerNurse / 6
Console.WriteLine($"每位护士负责病人数: {patientsPerNurse}"); // 输出7.5
// 计算轮班后剩余护士数
int remainingNurses = 15;
remainingNurses %= 4; // 计算分组后剩余,等同于 remainingNurses = remainingNurses % 4
Console.WriteLine($"分组后剩余护士数: {remainingNurses}"); // 输出3
Advantages of compound assignment operators:
- The code is simpler and easier to read
- Reduce duplicate writing of variable names
- Especially convenient when handling operations such as accumulation and subtraction
- Very useful for rapid updates of medical data
6. Sequential structure
The sequential structure is the most basic program structure: the program starts with the Main function and executes from top to bottom in the order in which the code is written. This is like when we perform nursing operations, we need to strictly follow a standardized sequence of steps.
1. basic sequential structure
// 患者入院登记流程
Console.WriteLine("请输入患者姓名:");
string patientName = Console.ReadLine();
Console.WriteLine("请输入患者年龄:");
int patientAge = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入患者体温:");
double temperature = Convert.ToDouble(Console.ReadLine());
// 按顺序显示患者信息
Console.WriteLine("患者信息汇总:");
Console.WriteLine($"姓名:{patientName}");
Console.WriteLine($"年龄:{patientAge}");
Console.WriteLine($"体温:{temperature}");
2. Branch structure: if, if-else
The branch structure is like our clinical decision-making path, performing different operations based on different conditions:
// 体温监测和处理流程
Console.WriteLine("请输入患者体温:");
double bodyTemp = Convert.ToDouble(Console.ReadLine());
if (bodyTemp >= 39.0)
{
Console.WriteLine("1. 立即通知医生");
Console.WriteLine("2. 进行物理降温");
Console.WriteLine("3. 密切监测生命体征");
}
else if (bodyTemp >= 37.3)
{
Console.WriteLine("1. 继续观察体温变化");
Console.WriteLine("2. 每小时测量一次体温");
}
else
{
Console.WriteLine("体温正常,继续常规护理");
}
3. Select structure: if-else if, switch-case
Use when multiple conditional judgments are needed, such as determining the treatment plan based on the patient's various indicators:
// 使用if-else if进行分诊
Console.WriteLine("请输入患者疼痛等级(0-10):");
int painLevel = Convert.ToInt32(Console.ReadLine());
if (painLevel >= 8)
{
Console.WriteLine("立即进入急救通道");
}
else if (painLevel >= 5)
{
Console.WriteLine("优先诊疗");
}
else if (painLevel >= 3)
{
Console.WriteLine("普通门诊就医");
}
else
{
Console.WriteLine("建议观察,必要时就医");
}
// 使用switch-case进行检查结果分类
Console.WriteLine("请输入检验结果等级(A/B/C/D):");
string resultLevel = Console.ReadLine().ToUpper();
switch (resultLevel)
{
case "A":
Console.WriteLine("检查结果正常");
break;
case "B":
Console.WriteLine("轻度异常,需要复查");
break;
case "C":
Console.WriteLine("中度异常,需要进一步检查");
break;
case "D":
Console.WriteLine("重度异常,需要立即处理");
break;
default:
Console.WriteLine("无效的等级输入");
break;
}
4. Importance of program structure
Just as in medical work, we need to follow standardized nursing procedures, the structure of the procedures also needs to be clear and orderly:
- The sequential structure ensures that the program follows the correct steps
- Branching structures help us handle different situations
- Choice structure makes complex conditional judgments clearer
- Good program structure improves code readability and maintainability
In medical information systems, the rational use of these program structures can help us:
- Standardize medical procedures
- reduce medical errors
- improve work efficiency
- ensure patient safety
learning experience
Today's study gave me a deeper understanding of programming. I found that many concepts in programming can be found in nursing work:
- Type conversion is like we unify the units of various test indicators
- Operators help us perform accurate medical data calculations
- Conditional judgment is strikingly similar to the decision-making process of the clinical pathway
- Logical operators are like the thought process we use when conducting a nursing assessment
These similarities not only make it easier for me to learn and understand, but also give me confidence in the future. I believe that my nursing background will not only be an obstacle to learning programming, but will instead be an advantage for me. Because in the wave of medical informatization, compound talents who understand both medical care and programming will play an important role.
Although the career transition is full of challenges, I believe that through continuous study and practice, I will be able to master this knowledge and contribute my part to the medical informatization cause.
I will continue to study other knowledge about C#in depth tomorrow, and let us look forward to the next sharing!