C#代码用法
1、new的用法
using System;
using System.Collections.Generic;
using System.Text;
namespace yanz
{
public class student
{
public string strName;
public student(string _strName)
{
this.strName=_strName;
}
}
class Program
{
static void Main(string[] args)
{
student s=new student("张三");
student t=new student("李四");
Console.WriteLine(t.strName);
Console.WriteLine(s.strName);
Console.ReadLine();
}
}
}
Student为类,“student s=new student("张三”);"中“s”代表张三
2、引用参数
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class myclass
{
public void Swap(ref int x,ref int y)
{
int k;
k=x;
x=y;
y=k;
}
}
class Program
{
static void Main(string[] args)
{
int a=8;b=10;
Console.WriteLine("a={0},b={1}",a,b);
myclass mycl=new myclass();
mycl.Swap(ref a,ref b);
Console.WriteLine("a={0},b={1}",a,b);
}
}
}
3、方法重载
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class student
{
public string strname;
public int nage;
public void grow()
{
this.nage++;
}
public void grow(int _nagespan)
{
this.nage +=_nagespan;
}
}
class Program
{
static void Main(string[] args)
{
student s=new student();
s.strname="zhangsan";
s.nage=20;
s.grow();
Console.WriteLine(s.nage);
s.grow(3);
Console.WriteLine(s.nage);
Console.ReadLine();
}
}
}
4、方法的调用
using System;
using System.Collections.Generic;
using System.Text;
namespace Example_ConstructOverload
{
class Time
{
public int nHour,nMinute,nSecond;
public Time()
{
nHour=nMinute=nSecond=0;
}
public Time(int Hour)
{
nHour=Hour;
nMinute=nSecond=0;
}
public Time(int Hour,int Minute)
{
nHour=Hour;
nMinute=Minute;
nSecond=0;
}
public Time(int hour,int Minute,int Second)
{
nHour=hour;
nMinute=Minute;
nSecond=Second;
}
}
class Test
{
static void Main()
{
Time t1,t2,t3,t4;
t1=new Time();
t2=new Time(10);
t3=new Time(10,20);
t4=new Time(10,22,30);
Console.WriteLine("t1的时间为:{0}时{1}分{2}秒",t1.nHour,t1.nMinute,t1.nSecond);
Console.WriteLine("t2的时间为:{0}时{1}分{2}秒:",t2.nHour,t2.nMinute,t2.nSecond);
Console.WriteLine("t3的时间为:{0}时{1}分{2}秒:",t3.nHour,t3.nMinute,t3.nSecond);
Console.WriteLine("t4的时间为:{0}时{1}分{2}秒:",t4.nHour,t4.nMinute,t4.nSecond);
Console.ReadLine();
}
}
}
C#代码用法的更多相关文章
- js跳转页面代码用法
一:window.location.href='https://www.baidu.com'; 需要加上http或者https,否则会查找项目内htm打开. 二:window.history.bac ...
- godot新手教程2[godot常用代码用法]
Godot概念: 在godot内,使用的语言是GDScript,大部分代码风格是和python一样. 在GDScript内代码段结束是换到下一行即可,不需要也不能添加”;”号,(注意:代码段结束后不能 ...
- discuz!代码内置颜色大全(收藏)
加闪烁字:[light]文字[/light] 加文字特效:[shadow=255,red,2]文字[/shadow]: 在标签的中间插入文字可以实现文字阴影特效,shadow内属性依次为宽度.颜色和边 ...
- 2-Qt关闭子窗口时执行特定代码
https://blog.csdn.net/naibozhuan3744/article/details/82689434 本文主要总结在关闭qt的QWidget子窗口瞬间,执行特定代码.由于主窗口关 ...
- log4j 简单用法
maven添加必要库: <!-- https://mvnrepository.com/artifact/log4j/log4j --> <dependency> <gro ...
- Less的用法
Less常用来写样式,比较多的用法是使用第三方软件编译成CSS文件,然后在HTML页面引入CSS文件.而不是直接在HTML页面里引入编译文件和Less文件.如此以来,在后期修改方便的多.当然,在写小项 ...
- [C/C++]快速读入代码(快读)
快读 1.为什么要有快读 好吧,有些题目看上去十分简单,例如https://www.luogu.com.cn/problem/P4305这道题,实际上数据量巨多,光是一个测试点就可能有几个MB,在这种 ...
- Python基础之函数:6、异常相关和生成器对象、yield用法、生成器表达式
目录 一.异常常见类型 1.类型错误 2.缩进错误 3.索引错误 4.语法错误 5.属性错误 6.key键错误 二.异常处理语法结构 1.基本语法结构 2.查看错误类型 3.针对不同类型所作措施 4. ...
- CanvasWebgl项目介绍
CanvasWebgl 介绍 CanvasWebgl 是一个基于webgl 开发的2d绘图框架,使用TypeScript开发 CanvasWebgl的功能,是在屏幕空间 或者 3D空间产生一个画布 ...
随机推荐
- Ubuntu16.04搭建LAMP开发环境
Ubuntu16.04搭建LAMP开发环境 虚拟机上安装好Ubuntu16.04后,是一台空白的Ubuntu.我的目的是搭建LAMP环境,顺便搭一个Python Django环境. 基本设置 1.配置 ...
- python tips;matplotlib 显示中文
import numpy as npimport matplotlib.pyplot as pltimport matplotlib as mpl mpl.rcParams['axes.unicode ...
- sersync+rsync作实时同事
http://liubao0312.blog.51cto.com/2213529/1677586 配置搞定,参照上面的文章,用时搞一搞就OK. 注意IPTABLES的配置及环境变量 最简陋配置: rs ...
- cl编译C文件的环境变量修改
添 加环境 变量INCLUDEC:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt;C:\Program Files (x8 ...
- localize by triangle note
1.当拟合结果不为1时,取和上次相近的作为结果2.python画三角拟合图bug (3.减小三角拟合波动:对激光雷达数据进行滤波等处理)(4.在计算三角起始和结束位置时,添加用距离值过滤) theta ...
- Count and Say (Array Length Encoding) -- LeetCode
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
- 【bzoj4950】【 [Wf2017]Mission Improbable】贪心+二分图匹配
(上不了p站我要死了,侵权度娘背锅) Description 那是春日里一个天气晴朗的好日子,你准备去见见你的老朋友Patrick,也是你之前的犯罪同伙.Patrick在编程竞赛 上豪赌输掉了一大笔钱 ...
- apache mod_speling.so 忽略URL大小写(自动纠错)
apache mod_speling.so 忽略URL大小写(自动纠错) 打开配置文件 httpd.conf 加入 LoadModule speling_module modules/mod_spe ...
- Systemd入门教程:实战篇(转)
作者: 阮一峰 日期: 2016年3月 8日 上一篇文章,我介绍了 Systemd 的主要命令,今天介绍如何使用它完成一些基本的任务. 一.开机启动 对于那些支持 Systemd 的软件,安装的时候, ...
- EDM邮件群发十大技巧提升邮件群发效果
有很多人抱怨现在邮件群发没有什么效果,其实不然,每一种推广方式都有他的优势,没有看到效果说明你没有掌握好方法.个人觉得EDM邮件群发的优势在于传播速度快.不受地域限制.不受时间限制.邮件内容能够多元化 ...