国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

C#and VB.net

2024-07-10 13:00:15
字體:
來源:轉載
供稿:網友


收集最實用的網頁特效代碼!

c#中的接口
interface
[public|protected|private] interface interfacename
{
//mothed
// propery
// event
//delegate
}
在實現接口時,帶接口名與不帶接口的區別
不帶的區別eg:
public interface imyshow
{
void show();
}
public class myshow:imyshow
{
public void show()//必須寫上前的public若寫成void show()出錯
{
system.console.write(" 不帶接口名");
}
}
public class mymain
{
public static void main()
{
// 用類定義引用
myshow obj=new myshow();
obj.show();
//用接口引用方法
imyshow obj2=new myshow();
obj2.show();

}
}

//帶接口名
public interface imyshow
{
system.console.write("帶接口名");
}
public class myshow:imyshow
{
void imyshow.show()// 前面不能帶上任何限定詞
{
system.console.write("帶接口名");
}
}
public class mymain
{
public static void main()
{
myshow obj=new myshow();
obj.show();//非法因為加了限定詞后,這個方法專屬于專們的一個引用,只能有接口去引用
imyshow obj2=new myshow();
obj2.show();

}
}
看完上面的內容我想為c#的愛好留個問題。請大家一起來討論一下
public interface imyshow
{
void show();
}
public interface imyshow2
{
void show();
}

public class myclass:imyshow,imyshow2
{
public myclass()
{

}

void imyshow.show()
{
system.console.write("imyshow");

}




public void show()
{
system.console.write("myclass show");
}

void imyshow2.show()
{
system.console.write("imyshow2.show()");

// todo: 添加 myclass.show 實現
}


}

class class1
{
/// <summary>
/// 應用程序的主入口點。
/// </summary>
[stathread]
static void main(string[] args)
{
imyshow obj2=new myclass ();
obj2.show();
imyshow obj1=new myclass();
obj1.show();
myclass obj=new myclass();
obj.show();

}
}
}

namespace wfgspace
public interface imyshow
sub show()
function add(byval a as integer, byval b as integer) as integer

end interface
public interface imyshow2
sub show()
function add(byval a as integer, byval b as integer) as integer

end interface
public class mycls : implements imyshow, imyshow2
private ivalue as integer

sub show() implements imyshow.show
system.console.write("wfng fu guo")
end sub
sub show2() implements imyshow2.show
system.console.write("wfg")

end sub
function add2(byval a as integer, byval b as integer) as integer implements imyshow.add, imyshow2.add


ivalue = a + b

system.console.writeline("{0}+{1}={2}", a, b, ivalue)
end function

end class
public class common
public shared sub main()
dim obj as mycls = new mycls
dim obj2 as imyshow = new mycls
dim obj3 as imyshow2 = new mycls
system.console.writeline("class mycls object")
obj.show2()
obj.add2(5, 4)

system.console.writeline("interface imyshow object")
obj2.show()
obj2.add(5, 4)
system.console.writeline("interface imyshow2 object")
obj3.show()
obj3.add(5, 4)

end sub
end class

end namespace



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富平县| 河间市| 潜江市| 永川市| 聂拉木县| 香港| 延吉市| 滨海县| 出国| 故城县| 南阳市| 耒阳市| 封开县| 隆回县| 保康县| 遂溪县| 林州市| 岳阳市| 杭州市| 英超| 北流市| 东山县| 西畴县| 普格县| 伊春市| 革吉县| 唐河县| 临沂市| 仙桃市| 星子县| 郓城县| 嘉鱼县| 类乌齐县| 汕头市| 咸丰县| 肇州县| 防城港市| 皋兰县| 邳州市| 嘉祥县| 武陟县|