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

首頁 > 開發 > 綜合 > 正文

17種Hello World!

2024-07-21 02:25:40
字體:
來源:轉載
供稿:網友


使用c#編寫不同的“hello world”程序

1. a beginners hello world
public class helloworld
{
public static void main()
{
system.console.writeline("hello world");
}
}
2. slightly improved version
using system;

public class helloworld
{
public static void main()
{
console.writeline("hello world");
}
}
3. command line arguments
using system;

public class helloworld
{
public static void main(string[] args)
{
console.writeline(args[0]);
}
}
4. from constructor
using system;
public class helloworld
{
public helloworld()
{
console.writeline("hello world");
}

public static void main()
{
helloworld hw = new helloworld();
}
}
5. more oo
using system;
public class helloworld
{
public void helloworld()
{
console.writeline("hello world");
}

public static void main()
{
helloworld hw = new helloworld();
hw.helloworld();
}
}
6. from another class
using system;
public class helloworld
{
public static void main()
{
helloworldhelperclass hwh = new helloworldhelperclass();
hwh.writehelloworld();
}
}

public class helloworldhelperclass
{
public void writehelloworld()
{
console.writeline("hello world");
}
}
7. inheritance
abstract class helloworldbase
{
public abstract void writehelloworld();
}
class helloworld : helloworldbase
{
public override void writehelloworld()
{
console.writeline("hello world");
}
}
class helloworldimp
{
static void main() {
helloworldbase hwb = helloworld;
helloworldbase.writehelloworld();
}
}
8. static constructor
using system;
public class helloworld
{
private static string strhelloworld;

static helloworld()
{
strhelloworld = "hello world";
}
void writehelloworld()
{
console.writeline(strhelloworld);
}

public static void main()
{
helloworld hw = new helloworld();
hw.writehelloworld();
}
}
9. exception handling
using system;

public class helloworld
{
public static void main(string[] args)
{
try
{
console.writeline(args[0]);
}
catch(indexoutofrangeexception e)
{
console.writeline(e.tostring());
}
}
}
10. creating a dll and using it in an application
using system;

namespace hellolibrary
{
public class hellomessage
{
public string message
{
get
{
return "hello, world!!!";
}
}
}
}

//------

using system;
using hellolibrary;

namespace helloapplication
{
class helloapp
{

public static void main(string[] args)
{
hellomessage m = new hellomessage();

}
}
}
11. using property
using system;
public class helloworld
{
public string strhelloworld
{
get
{
return "hello world";
}
}

public static void main()
{
helloworld hw = new helloworld();
console.writeline(cs.strhelloworld);
}
}
12. using delegates
using system;
class helloworld
{
static void writehelloworld() {
console.writeline("helloworld");
}
static void main() {
simpledelegate d = new simpledelegate(writehelloworld);
d();
}
}
13. using attributes
#define debugging

using system;
using system.diagnostics;

public class helloworld : attribute
{
[conditional("debugging")]

public void writehelloworld()
{
console.writeline("hello world");
}

public static void main()
{
helloworld hw = new helloworld();

hw.writehelloworld();
}
}
14. using interfaces
using system;

interface ihelloworld
{
void writehelloworld();
}

public class helloworld : ihelloworld
{
public void writehelloworld()
{
console.writeline("hello world");
}

public static void main()
{
helloworld hw = new helloworld();

hw.writehelloworld();
}
}
15. dynamic hello world
using system;
using system.reflection;

namespace helloworldns
{

public class helloworld
{
public string writehelloworld()
{
return "helloworld";
}

public static void main(string[] args)
{
type hw = type.gettype(args[0]);

// instantiating a class dynamically

object[] nctorparams = new object[] {};
object nobj = activator.createinstance(hw,
nctorparams);

// invoking a method

object[] nmthdparams = new object[] {};
string strhelloworld = (string) hw.invokemember(
"writehelloworld", bindingflags.default |
bindingflags.invokemethod, null,
nobj, nmthdparams);

console.writeline(strhelloworld);
}
}
}
16. unsafe hello world
using system;

public class helloworld
{
unsafe public void writehelloworld(char[] chrarray)
{
fixed(char *parr = chrarray)
{
char *pch = parr;
for(int i=0; i<chrarray.length; i++)
console.write(*(pch+i));
}
}

public static void main()
{
helloworld hw = new helloworld();
char[] chrhelloworld = new char[]
{'h','e','l','l','o', ' ', 'w','o','r','l','d'};
hw.writehelloworld(chrhelloworld);
}
}
17. using interopservices
using system;
using system.runtime.interopservices;

class class1
{
[dllimport("kernel32")]
private static extern int beep(int dwfreq, int dwduration);

static void main(string[] args)
{
console.writeline("hello world");
beep(1000, 2000);
}
}

商業源碼熱門下載www.html.org.cn

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鲁山县| 陆河县| 冷水江市| 丹阳市| 高雄县| 雷州市| 姚安县| 任丘市| 定远县| 龙泉市| 和平区| 上思县| 罗甸县| 淮北市| 平安县| 尤溪县| 渭源县| 交口县| 登封市| 尉犁县| 松江区| 巢湖市| 虹口区| 黔西| 工布江达县| 桂阳县| 永清县| 张家界市| 枞阳县| 永福县| 衡东县| 涟水县| 弥勒县| 浦东新区| 中卫市| 淅川县| 洪湖市| 腾冲县| 汤原县| 中山市| 大英县|