Answer the question
In order to leave comments, you need to log in
How to shorten a condition?
There are several conditions where one of several names is checked for a match + the current temperature
if ((name == "SiO2 (β-кварц)" || name == "SiO2 (α-кварц)" || name == "SiO2 (α-тридимит)" || name == "SiO2 (β-кристобалит)" || name == "SiO2(к) кварц" || name == "SiO2(к) тридимит" || name == "SiO2(к) кристобалит" || name == "SiO2 (полиморф.)") && curTemp <= 846.15)
{
h = -217.75F; s = 10F; a = 11.22F; b = 8.2F; c = -2.7F;
}
else if((name == "SiO2 (β-кварц)" || name == "SiO2 (α-кварц)" || name == "SiO2 (α-тридимит)" || name == "SiO2 (β-кристобалит)" || name == "SiO2(к) кварц" || name == "SiO2(к) тридимит" || name == "SiO2(к) кристобалит" || name == "SiO2 (полиморф.)") && curTemp >= 846.15)
{
h = -217.6F; s = 0F; a = 14.41F; b = 1.94F; c = 0F;
}
else if ((name == "SiO2 (β-кварц)" || name == "SiO2 (α-кварц)" || name == "SiO2 (α-тридимит)" || name == "SiO2 (β-кристобалит)" || name == "SiO2(к) кварц" || name == "SiO2(к) тридимит" || name == "SiO2(к) кристобалит" || name == "SiO2 (полиморф.)") && curTemp >= 1143.15)
{
h = -216.5F; s = 10.4F; a = 13.64F; b = 2.64F; c = 0F;
}
else if ((name == "SiO2 (β-кварц)" || name == "SiO2 (α-кварц)" || name == "SiO2 (α-тридимит)" || name == "SiO2 (β-кристобалит)" || name == "SiO2(к) кварц" || name == "SiO2(к) тридимит" || name == "SiO2(к) кристобалит" || name == "SiO2 (полиморф.)") && curTemp >= 1743.15)
{
h = -215.95F; s = 10.19F; a = 4.28F; b = 21.06F; c = 0F;
}
Answer the question
In order to leave comments, you need to log in
private static string[] _elementNames = new[] { "SiO2 (β-кварц)", "and", "more"};
....
if (_elementNames.Contains(name))
{
if (curTemp <= 846.15)
{
h = -217.75F;
s = 10F;
a = 11.22F;
b = 8.2F;
c = -2.7F;
}
else if (....) { ....}
....
}
It suggests Dictionary https://docs.microsoft.com/ru-ru/dotnet/api/system...
where the key will be name, and the value will be a primitive class/structure of 4 fields
, and then the initialization of the dictionary will be placed in a separate block (and for example it will be possible to load it from storage)
and search:
h=Dic[""SiO2 (β-quartz)""].h;
s=Dic[""SiO2 (β-quartz)""].s;
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question