我有兩個具有相同名稱的函數,主要區別僅僅是不同的返回類型。我怎麼能以使用相同的名稱,因爲有時我需要三維點或point3f陣列重載函數,下面的函數名給出錯誤是相同的:具有不同返回類型的超載函數
public static Point3d[] GetNGonCenters(this Mesh mesh)
{
Point3d[] centers = new Point3d[mesh.Ngons.Count];
for (int i = 0; i < mesh.Ngons.Count; i++)
centers[i] = mesh.Ngons.GetNgonCenter(i);
return centers;
}
public static Point3f[] GetNGonCenters(this Mesh mesh)
{
Point3f[] centers = new Point3f[mesh.Ngons.Count];
for (int i = 0; i < mesh.Ngons.Count; i++)
centers[i] = (Point3f)mesh.Ngons.GetNgonCenter(i);
return centers;
}
你只能超負荷方法參數,而不是返回類型。 – Phylogenesis
你不能在返回類型上重載函數 – ali
另一種選擇是爲擴展方法創建一個不同的靜態類。如果它們位於不同的類中,則重載不會成爲問題。 – RobPethi