代码查询和调试

代码查询

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace m1w2d6_debug
{
struct Point2d
{
}
class Program
{
static void Main(string[] args)
{
#region 代码查询
//查询类型
//右键点击需要查询的类型,选择转到定义
//将鼠标悬停在对应的方法上
//可以知道这个方法的返回值和参数,还可以知道他是否有不同的重载
Point2d p = new Point2d();
String s = " 字符串 ";
//类名调用方法 如果定义中 有static关键字 就是用类名调用的方法
bool isNull = string.IsNullOrEmpty(s);//string 和 String 特殊的系统类型的别称
Console.WriteLine(isNull ? "是空串" : "不是空串");
//变量调用方法 如果定义中 没有static关键字 就是用变量调用方法
Console.WriteLine(s.Length);
Console.WriteLine(s);
s = s.Trim();
Console.WriteLine(s.Length);
Console.WriteLine(s);
//看API学习Split(重载)和SubString方法
//String.Split 方法有6个重载函数:
string str = "attack,defend,health,speed";
char[] chars = { '' };
//1、用字符串分隔:
string str1 = "aaajsbbbjsccc";
string[] sArray1 = Regex.Split(str1, "js", RegexOptions.IgnoreCase);
foreach (string i in sArray1) Console.Write(i.ToString() + "\r\n");
Console.WriteLine("\r\n");
//输出结果:
//aaa
//bbb
//ccc
//2、用多个字符来分隔:
string str2 = "aaajbbbscccjdddseee";
string[] sArray2 = str2.Split(new char[] { 'j', 's' });
foreach (string i in sArray2) Console.Write(i.ToString() + "\r\n");
Console.WriteLine("\r\n");
//输出结果:
//aaa
//bbb
//ccc
//ddd
//eee
//3、用单个字符来分隔:
string str3 = "aaajbbbjccc";
string[] sArray3 = str3.Split('j');
foreach (string i in sArray3) Console.Write(i.ToString() + "\r\n");
Console.WriteLine("\r\n");
//输出结果:
//aaa
//bbb
//ccc
//SubString 方法:
//程序代码
//程序代码
string str = "abcdefgh";
Response.Write(str.Substring(, ));//return:a
Response.Write(str.Substring(, ));//return:cde
Response.Write(str.Substring(, ));//return:h
Response.Write(str.Substring());//return:h
Response.Write(str.Substring());//error:startIndex 不能大于字符串长度。
Response.Write(str.Substring(, ));//error:索引和长度必须引用该字符串内的位置。
#endregion
#region 代码调试
//
int count = ;
while (true)
{
Console.WriteLine(count++);
Console.WriteLine("我要学好C#");
}
#endregion
}
}
}

代码调试

打开调试窗口

函数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace m1w2d6_function_flyingchess
{
class Program
{
//比较两个数字的大小,返回最大值。
//对 两个数字 做 比大小 ,要最大的那个
static int GetMax(int a, int b)//要在主函数中使用,主函数是static,所以要加static
{
return a > b ? a : b;
}
//写一个方法,判定你传入的参数是不是质数。
//对 对谁(参数) 做什么(函数体) 结果如何(返回类型)
//对 一个数 判定是否是质数 告诉我是或者不是(打印,返回)
static void GetNum(int num)
{
for (int i = ; i < num; i++)
{
if (num%i==)
{
Console.WriteLine("不是质数");
}
}
Console.WriteLine("是质数");
}
static void GetNum1(int num)
{
for (int i = ; i < num; i++)
{
if (num % i == )
{
Console.WriteLine("{0}不是质数", i);
}
Console.WriteLine("{0}是质数", i);
}
}
//圆的周长和面积
static float[] GetCircle(int r)
{
float PI = 3.1415926f;
float area = r * r * PI;
float perimeter = * r * PI;
float[] array = new float[] { area, perimeter };
return (array);
}
//数组计算
static void GetArray(int[] array)
{
float sum = 0f;
int max = ;
int min = ;
float average = 0f;
for (int i = ; i < array.Length - ; i++)
{
sum += array[i];
if (array[i] > max)
{
max = array[i];
}
else if (array[i] < min)
{
min = array[i];
}
average = sum / array.Length - ;
}
Console.WriteLine("总和是{0}", sum);
Console.WriteLine("最大是{0}", max);
Console.WriteLine("最小是{0}", min);
Console.WriteLine("平均是{0}", average);
}
//数组排序
static int[] GetArrayRank(int[] array)
{
for (int i = ; i < array.Length - ; i++)
{
for (int j = ; j < array.Length - - i; j++)
{
if (array[j] > array[j + ])
{
int temp = array[j];
array[j] = array[j + ];
array[j + ] = temp;
}
}
}
return array;
}
//判断闰年
static void GetYear(int year)
{
while (true)
{
if (year % == || year % == && year % != )
{
Console.WriteLine("是闰年");break;
}
}
}
static void Main(string[] args)
{
//函数是对逻辑(语句序列)的封装,方便以后重复使用
//函数的签名{函数体}
//指令逻辑(什么指令) 对谁(参数) 做什么(函数体) 结果如何(返回类型)
//参数 可以是任意类型
//函数体 可以是任意语句
//返回类型 可以是任意类型 void(无返回类型)
//如果指定了返回类型 必须有相应的返回值
//使用return可以返回一个值,并结束函数
//如果你使用了void,也可以使用return,这时,他不再返回值,但结束函数
//返回类型 函数名 (参数列表)
//{
// 函数体
//}
int max = GetMax(, );//函数如果有返回类型,你可以直接使用函数返回值
Console.WriteLine(max);
//void无返回值
GetNum();
GetNum1();
//圆的周长和面积
float[] sArray1 = new float[];
sArray1 = GetCircle();
foreach (float i in sArray1) Console.Write(i.ToString() + "\r\n");
//数组计算
int[] sArray2 = new int[] { , , , };
GetArray(sArray2);
//数组排序
int[] sArray3 = new int[] { , , , , , , , , , };
foreach (float i in sArray3) Console.Write(i.ToString() + "\t");
Console.WriteLine("\r\n");
sArray3 = GetArrayRank(sArray3);
foreach (float i in sArray3) Console.Write(i.ToString() + "\t");
Console.WriteLine("\r\n");
//判断闰年
int year = int.Parse(Console.ReadLine());
GetYear(year); }
}
}

C#学习笔记(九):函数、代码查询和调试的更多相关文章

  1. python学习笔记(九)函数返回多个值,列表生成式,循环多个变量,入参格式声明

    一.函数返回多个值 1.函数如果返回多个值的话,它会把这几个值放到一个元组里面2.函数如果返回多个值的话,也可以用多个变量来接收 def say(): num1 = num2 = num3 = ret ...

  2. python学习笔记(九)-函数2

    交换两个变量的值 a = 2 b = 1 b = 1 a = 2 #方式一: b,a = a,b #交换两个变量的值 print(a,b) #方式二: a = a + b #3 b = a - b # ...

  3. swift学习笔记2——函数、闭包

    之前学习swift时的个人笔记,根据github:the-swift-programming-language-in-chinese学习.总结,将重要的内容提取,加以理解后整理为学习笔记,方便以后查询 ...

  4. MDX导航结构层次:《Microsoft SQL Server 2008 MDX Step by Step》学习笔记九

    <Microsoft SQL Server 2008 MDX Step by Step>学习笔记九:导航结构层次   SQL Server 2008中SQL应用系列及BI笔记系列--目录索 ...

  5. go微服务框架kratos学习笔记九(kratos 全链路追踪 zipkin)

    目录 go微服务框架kratos学习笔记九(kratos 全链路追踪 zipkin) zipkin使用demo 数据持久化 go微服务框架kratos学习笔记九(kratos 全链路追踪 zipkin ...

  6. matlab学习笔记 bsxfun函数

    matlab学习笔记 bsxfun函数 最近总是遇到 bsxfun这个函数,前几次因为无关紧要只是大概看了一下函数体去对比结果,今天再一次遇见了这个函数,想想还是有必要掌握的,遂查了些资料总结如下. ...

  7. SQL反模式学习笔记18 减少SQL查询数据,避免使用一条SQL语句解决复杂问题

    目标:减少SQL查询数据,避免使用一条SQL语句解决复杂问题 反模式:视图使用一步操作,单个SQL语句解决复杂问题 使用一个查询来获得所有结果的最常见后果就是产生了一个笛卡尔积.导致查询性能降低. 如 ...

  8. jQuery 学习笔记:jQuery 代码结构

    jQuery 学习笔记:jQuery 代码结构 这是我学习 jQuery 过程中整理的笔记,这一部分主要包括 jQuery 的代码最外层的结构,写出来整理自己的学习成果,有错误欢迎指出. jQuery ...

  9. matlab学习笔记13_1 函数返回值

    一起来学matlab-matlab学习笔记13函数 13_1 函数返回值 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 https://blog.csdn.net/qq_36556 ...

随机推荐

  1. extjs中的store

    1.store中重要的属性和方法 属性:data.proxy.reader.url.root .... 方法:load 2.理解:data--原料,proxy--运输车,reader--加工厂,sto ...

  2. mysql transaction 事务

    1.事务简介 一个"最小的"不可再分的"工作单元". 一个事务通常对应了一个完整的业务.如:银行的转账功能,a转账给b,a扣钱,b加钱. 一个事务包含一条或多条 ...

  3. android 操作SD卡上的文件

    (1)说明:操作SD卡上的文件须要增加下面权限  在SD卡上创建和删除文件权限  <uses-permission android:name="android.permission.M ...

  4. 万恶之源 - Python基础

    Python简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程 ...

  5. POJ1062:昂贵的聘礼(枚举+迪杰斯特拉)

    http://poj.org/problem?id=1062 Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为 ...

  6. POJ1789:Truck History(Prim算法)

    http://poj.org/problem?id=1789 Description Advanced Cargo Movement, Ltd. uses trucks of different ty ...

  7. openstack部署心得

    官方文档:https://docs.openstack.org/ 个别版本有中文 不要轻易尝试最新版本 新版本刚推出一般存在不少BUG或者文档没有更新,按照文档配置就是不能成功.推荐尝试最新版本的上一 ...

  8. window7 触屏操作相关

    一.体系概述 1.Windows Touch Input 和 Gestures消息 Windows Touch消息特性 通过在执行期间的监听和解释来使能.下面的示例展示了Windows7 上消息是怎么 ...

  9. python接口测试中安装whl格式的requests第三方模块

    下载 安装 requests第三方模块 下载:http://docs.python-requests.org/en/latest/user/install/#install 我下载是 https:// ...

  10. [LeetCode] 532. K-diff Pairs in an Array_Easy tag: Hash Table

    Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in t ...