该方法如下所示:
private static List<string> SetPointObjectDefectRow(string[] row, string owner)
{
const int zone = 54;
const string band = "U";
if (Helpers.NormalizeLocalizedString(row[7]).Contains(@"a") ||
Helpers.NormalizeLocalizedString(row[12]).Contains(@"b"))
{
var geoPosition = UtmConverter.StringUtmFormatToLocation(zone, band, Convert.ToDouble(row[15]), Convert.ToDouble(row[14]));
var beginGeoPosition = geoPosition.LatString + ", " + geoPosition.LngString;
var result = new List<string>
{
owner,
row[4],
beginGeoPosition
};
return result;
}
}
很明显,并非所有路径都返回了某些内容,而问题是我无法返回null。
如何重新排列方法?
答案 0 :(得分:2)
也许你可以初始化你的名单?
private static List<string> SetPointObjectDefectRow(string[] row, string owner)
{
const int zone = 54;
const string band = "U";
List<string> result = new List<string>()
{
owner,
string.Empty,
string.Empty
};
if (Helpers.NormalizeLocalizedString(row[7]).Contains(@"a") ||
Helpers.NormalizeLocalizedString(row[12]).Contains(@"b"))
{
var geoPosition = UtmConverter.StringUtmFormatToLocation(zone, band, Convert.ToDouble(row[15]), Convert.ToDouble(row[14]));
var beginGeoPosition = geoPosition.LatString + ", " + geoPosition.LngString;
result = new List<string>
{
owner,
row[4],
beginGeoPosition
};
}
return result;
}
我想在创建汇编程序方法时执行此操作,例如将List<X>
转换为另一个List<Y>
,因此如果我的List<X>
为null,我会尝试返回一个空列表我喜欢这样做,而不是抛出异常并让我的仪表板充满错误。但这取决于你的代码如何工作。