C#总结(3)
这次我们来谈谈函数。
C#的函数分为静态函数,和普通函数。
先上代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace CS总结3
{
class Program
{
static void Main(string[] args)
{
Program.Show1();
Program x = new Program();
x.Show2();
} static void Show1()
{
Console.WriteLine("调用静态函数");
}
void Show2()
{
Console.WriteLine("调用普通函数");
}
}
}
所看到的结果:
可以看到,静态函数可以通过类名调用,当然,在本类中,静态Main方法其实可以直接调用本身的静态方法。
而普通方法,是存在在类当中的,只有创建该类的实例,才能调用里面的普通函数。
再上一个代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace CS总结3
{
class Program
{
static void Main(string[] args)
{
Program.Show1();
Program x = new Program();
x.Show2();
if (i < )
{
++i;
Console.WriteLine(i);
Program.Main(null); }
}
static int i = ;
static void Show1()
{
Console.WriteLine("调用静态函数");
}
void Show2()
{
Console.WriteLine("调用普通函数");
}
}
}
这是一个递归调用Main函数的程序,调用了101次。
随机推荐
- iOS_SN_Socket网络编程(一)
1.Socket简介 首先让我们通过一张图知道socket在哪里? socket在哪里 Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口. 2.TCP和UDP的区别 在这里就 ...
- C#将十六进制的文本转换到整型数据
1 length1 = Int32.Parse(szLine.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);//计算这一行 ...
- 为什么memset不能将数组元素初始化为1?
原型:extern void *memset(void *buffer, int c, int count); 功能:把buffer所指内存区域的前count个字节设置成字符c. 包含头文件:< ...
- ORA-01722: invalid number,ORA-12801
SQL: SELECT /*+ parallel(a,32) */ a.id ,a.data_date ,a.mobile_num ,a.mobile_code ,b.prov AS mobile_p ...
- Aphache VFS
http://blog.csdn.net/hemingwang0902/article/details/4733911 http://jackyrong.iteye.com/blog/1330946 ...
- Ubuntu 修改 Apache2 用户组 方法
检查/etc/apache2/envvars文件,发现其中需要使用/etc/apache2/envvars文件中的以下几个环境变量 export APACHE_RUN_USER=www-data ex ...
- Bash: how to check if a process id (PID) exists
http://stackoverflow.com/questions/3043978/bash-how-to-check-if-a-process-id-pid-exists https://bugz ...
- LeetCode_Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...
- Qt自定义带游标的slider,在滑块正上方显示当前值(非常有意思,继承QSlider之后增加一个QLabel,然后不断移动它)
首先自定义QSlider的子类MyCustomSlider,如下所示. mycustomslider.h #ifndef MYCUSTOMSLIDER_H #define MYCUSTOMSLIDER ...
- PowerShell_零基础自学课程_8_高级主题:WMI对象和COM组件
本系列文章从最初的初识开始,基本上可以完成一些简单的系统管理了,为了更方便的管理系统,同时为了更好的发掘系统的性能,就需要用到系统提供 的一些高级特性,在Windows Server系列的OS中,如果 ...