C#部分---函数添加基本格式;
格式1:没有参数,没有返回值 (无参无返)
添加函数:
/// <summary>
/// 累加求和的方法,没有参数,没有返回值
/// </summary>
public void LeiJia()
{
//累加求和
Console.Write("请输入一个正整数:");
int a = int.Parse(Console.ReadLine());
int sum = ;
for (int i = ; i <= a; i++)
{
sum += i;
}
Console.WriteLine("总和是" + sum);
}
(主函数里面的写法:)
static void Main(string[] args)
{ //实例化 初始化 这个类
Program hanshu = new Program();
//hanshu.First();
//格式1调用
//hanshu.LeiJia(); }
//格式2:没有返回值,有参数(有参无返)
添加函数:
/// <summary>
/// 累加求和,需要一个int类型的参数,没返回值
/// </summary>
/// <param name="d"></param>
public void LeiJia(int d)
{
int sum = ;
for (int i = ; i <= d; i++)
{
sum += i;
}
Console.WriteLine("总和是" + sum);
}
(主函数里面的写法):
static void Main(string[] args)
{
//实例化 初始化 这个类
Program hanshu = new Program();
//格式2调用
//Console.Write("请输入一个正整数:");
//int a = int.Parse(Console.ReadLine());
//hanshu.LeiJia(a);
}
//格式3:有参数,有返回值(有参有返)
添加函数:
/// <summary>
/// 累加求和,需要参数,也有返回值
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
public int Leijia1(int d)
{
int sum = ;
for (int i = ; i <= d; i++)
{
sum += i;
}
return sum;
}
(在主函数中的写法:)
static void Main(string[] args)
{
//实例化 初始化 这个类
Program hanshu = new Program();
//格式3调用
//Console.Write("请输入一个正整数:");
//int a = int.Parse(Console.ReadLine());
//int sum = hanshu.Leijia1(a);
//Console.WriteLine(sum);
}
//格式4:没有参数,有返回值
添加函数:
/// <summary>
/// 累加求和,没有参数,但是有返回值(int)
/// </summary>
/// <returns></returns>
public int Leijia2()
{
Console.Write("请输入一个正整数:");
int a = int.Parse(Console.ReadLine());
int sum = ;
for (int i = ; i <= a;i++ )
{
sum += i;
}
return sum;
}
(在主函数中的写法:)
static void Main(string[] args)
{
//实例化 初始化 这个类
Program hanshu = new Program();
;
//格式4调用
//int sum =hanshu.Leijia2();
//Console.WriteLine(sum);
}
格式3中有两个或多个变量时,有参有返例如比较大小
两个数比较大小返回较大的一个
添加函数:
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public double Max(double a , double b)
{
if (a >= b)
{
return a;
}
else
{
return b;
}
}
(主函数中的写法:)
static void Main(string[] args)
{
//实例化 初始化 这个类
Program hanshu = new Program();
//比较大小
double a = ;
double b = ;
double c = ;
Console.WriteLine(hanshu.Max(hanshu.Max(a, b), c)); ;
}
C#部分---函数添加基本格式;的更多相关文章
- C# 代码往oracle数据库添加datetime格式列
C# 代码往oracle数据库添加datetime格式列时,不需要在insert语句中为datetime类型使用to_date函数
- SQLserver中用convert函数转换日期格式
SQLserver中用convert函数转换日期格式 2008-01-23 15:47 SQLserver中用convert函数转换日期格式2008-01-15 15:51SQLserver中用con ...
- 第八十八天请假 PHP smarty模板 变量调节器,方法和块函数基本书写格式
变量调节器 : 文件命名格式(modifier.名称.php) 前端调用方式<{变量|名称:参数:参数……}>可组合使用,用|隔开 <?php /* 命名格式 smarty_mod ...
- 使用VAssistX给文件和函数添加注释-2015.12.31
在Visual Studio使用VAssistX助手可以非常方便的给文件和函数添加注释,增加更多的记录信息,从而方便在时间久后,对代码阅读理解的提示,以及别人后续对代码的维护和BUG修改. 添加头文件 ...
- main函数的正确格式
main函数称之为主函数,一个C程序总是从main()函数开始执行的.在关于C语言的网贴和图书中,可以看到main函数的多种格式,这些格式,有的是正确的,有的是不正确的,为了避免错误,现归纳整理如下. ...
- [php基础]Mysql日期函数:日期时间格式转换函数详解
在PHP网站开发中,Mysql数据库设计中日期时间字段必不可少,由于Mysql日期函数输出的日期格式与PHP日期函数之间的日期格式兼容性不够,这就需要根据网站实际情况使用Mysql或PHP日期转换函数 ...
- GDAL添加ECW格式支持
目录 GDAL添加ECW格式支持 ECW 下载ECW JPEG SDK 在Unix平台构建支持ECW的GDAL 二进制ECW SDK和GCC >= 5.1 在Linux上构建的教程 在Windo ...
- AppendMenu函数添加菜单
这个函数添加新项目到指定菜单的末尾.你可以使用appendmenu指定内容,外观,和菜单项行为. BOOL AppendMenu( HMENU hMenu, UINT uFlags, UINT uID ...
- python cookbook第三版学习笔记十九:未包装的函数添加参数
比如有下面如下的代码,每个函数都需要判断debug的是否为True,而默认的debug为False def a(x,debug=False): if debug: print('calling a') ...
随机推荐
- Spring学习笔记之模块简介
1.Core Container(Application context) module 这个是Spring最基本的模块,它提供了spring框架最基本的功能.BeanFactory 是任何基于Spr ...
- swift语言开发的一个游戏------熊猫跑酷(KongfuPanda)
项目地址:https://github.com/jakciehoo/KongfuPanda 欢迎加QQ群:260558552.大家一起交流iOS开发,我们可以一起学习,我很想集结一些志同道合的朋友,一 ...
- NSString和data转换
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); NS ...
- WABAPI使用
最近写一个供其他系统调用的接口,决定使用wabapi,以前只是大概了解wabapi是什么东西,没有写过自己的api,从头开始学习. 1.开始创建一个webapi的项目,不得不说VS真的替我们省了好多事 ...
- Android Context
http://www.cnblogs.com/android100/p/Android-Context.html
- 子线程简单实现(ZT)
4.0以后的android在主线程中不可以直接访问网络,就得用以下的方法来搞,嘿嘿 在主函数中发送一个空的消息 : new Thread(){ @Override public void run() ...
- Palindrome Number ---- LeetCode 009
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- two Sum ---- LeetCode 001
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- css if hack之兼容ie
1.Css if hack条件语法< !--[if IE]> Only IE <![endif]-->仅所有的WIN系统自带IE可识别< !--[if IE 5.0]&g ...
- Blocks_DP&&矩阵快速幂
参考资料:http://www.tuicool.com/articles/beiyAv [题意]有n块砖.现要将砖全部染上红.蓝.绿.黄四种颜色.要求被染成红色和绿色的砖块数量必须为偶数,问一共有多少 ...