用于环路转换器
本文关键字:转换器 环路 用于 | 更新日期: 2023-09-27 18:00:18
我知道有一些类似vb到c#转换器的应用程序,但我想要的有点不同。我需要一个转换器来帮助我将这个"for"循环转换为"while"循环。这是我为"Integer Factory"设计的代码(你可以看到底部的"for"循环——这是需要转换的内容)。我还有一些其他循环,这就是为什么我需要一个应用程序(最好是wysiwyg)。谢谢
int IntegerBuilderFactory(string stringtobeconvertedbythefactory)
{
string strtmp = stringtobeconvertedbythefactory;
int customvariabletocontrolthethrottling;
if (strtmp.Length > 0)
{
customvariabletocontrolthethrottling = 1;
}
else
{
customvariabletocontrolthethrottling = 0;
}
for (int integersforconversiontostrings = 0; integersforconversiontostrings < customvariabletocontrolthethrottling; integersforconversiontostrings++)
{
return int.Parse(strtmp);
}
try
{
return 0;
}
catch (Exception ex)
{
// Add logging later, once the "try" is working correctly
return 0;
}
}
每个for循环(for(initializer;condition;iterator)body;
)本质上都是
{
initializer;
while(condition)
{
body;
iterator;
}
}
现在,您可以利用这些知识为您选择的重构工具创建代码转换。
顺便说一下,那个代码看起来很糟糕。。。
int IntegerBuilderFactory(string stringToParse)
{
int result;
if(!int.TryParse(stringToParse, out result))
{
// insert logging here
return 0;
}
return result;
}
完成。
int integersforconversiontostrings = 0;
while (integersforconversiontostrings < customvariabletocontrolthethrottling)
{
return int.Parse(strtmp);
integersforconversiontostrings++
}