国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吉安县| 邛崃市| 成安县| 怀安县| 邵东县| 塔河县| 新竹县| 徐州市| 商南县| 民和| 哈密市| 延边| 铜陵市| 青州市| 馆陶县| 老河口市| 光泽县| 三门峡市| 翁牛特旗| 南和县| 商城县| 靖远县| 会同县| 沧源| 岱山县| 平陆县| 丹阳市| 肃宁县| 曲阳县| 柳江县| 申扎县| 四会市| 建德市| 漠河县| 香河县| 莒南县| 临潭县| 临漳县| 延长县| 汾西县| 临漳县|