2
A
回答
0
我认为你的意思是运行时多态(方法重载)。我不认为你可以用Structs做到这一点,因为结构不支持继承。
您可能要参考this article或this article
0
我认为我们可以做编译时多态性但不是Runtime.I尝试以下代码,并让我惊讶它的工作!
我试过的代码和编译时间多态性是允许的。代码是在下面,但为什么运行时多态性是不允许的我没有得到,但现在,我想我得到了解决方案。
任何意见或guidline表示赞赏。
using System;
struct SimpleStruct
{
private int xval;
public int X
{
get
{
return xval;
}
set
{
if (value < 100)
xval = value;
}
}
public void DisplayX()
{
Console.WriteLine("The stored value is: {0}", xval);
}
public void DisplayX(int a)
{
Console.WriteLine("The stored value is: {0}", a);
}
}
class TestClass
{
public static void Main()
{
SimpleStruct ss = new SimpleStruct();
ss.X = 5;
ss.DisplayX();
ss.DisplayX(3);
Console.ReadLine();
}
}
0
嗯,我想这样一个事实:结构可以实现接口...
例如:
public interface IPoint
{
int X {get;set;}
int Y {get;set;}
}
public struct Point : IPoint
{
public int X { get; set; }
public int Y { get; set;}
}
public struct AnotherPoint : IPoint
{
public int X { get; set; }
public int Y { get; set; }
}
public static void Main() {
var arr = new IPoint [2];
arr [0] = new Point() { X = 2 };
arr [1] = new AnotherPoint() { X = 7 };
foreach (var p in arr) {
Console.WriteLine (p.X);
}
Console.ReadKey();
}
相关问题
- 1. 我们可以在c#中使用接口实现多态吗?
- 2. 我们可以在FM上实现静态选择'ALL'吗?
- 3. 我们可以使用xcode在Facebook中实现autoshare吗?
- 4. 我们可以在Java中实现XOR链表吗?
- 5. 我们可以在JavaFX中实现我们自己的材料吗?
- 6. JPA2:我们可以在实体中使用多个@ElementCollection吗?
- 7. 我们真的需要类来实现Java中的多态吗?
- 8. 我可以在C++中实现多个回调接口吗?
- 9. 现在我们可以在DjEng中使用GAE中的ORM吗?
- 10. 我们可以使用继承来实现链表吗?
- 11. 我们可以改变一个函数的实现吗?
- 12. 我们可以说“C语言运算符是多态的”吗?
- 13. 我们可以在Web服务类中实现方法重载吗?
- 14. 我们可以在本机iPhone应用程序中实现openID选项吗?
- 15. 我们可以在目标c中使用接口和实现文件吗?
- 16. 我们可以在现有项目中配置maven吗?
- 17. 可以在Xamarin.Android中实现android.support.v7.util.sortedlist吗?
- 18. 我可以使用增强现实吗?
- 19. 我可以自动实现类吗?
- 20. 我们可以在MySQL中动态创建表吗?
- 21. 我们可以让Liferay在私有云中动态扩展吗?
- 22. 我们可以在tclOO中定义静态函数吗?
- 23. 我们可以避免在java中实习字符串吗?
- 24. 我们可以在实践中使用CSS 2.1选择器吗?
- 25. 我们可以在Zends delete()中使用多个where子句吗?
- 26. 我们可以在Docker中运行多进程程序吗?
- 27. 我们可以在TableLayoutPanel中显示多个DataGridView吗?
- 28. 我们可以在HTML中嵌入多个视频吗?
- 29. 我们可以在Django中使用很多views.py作为Controller吗?
- 30. 我们可以在表中有多个标识列吗?
你能提供一些代码?只是为了争辩你的帖子? –