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空间产生一个画布 ...
随机推荐
- javascript验证前端页面
数据表结构 1.html页面 <!DOCTYPE html> <html> <head> <title>注册</title> <met ...
- 5.DataFrame(基本概念)
- linux Centos7 安装Samba服务
1. 使用Samba服务器需要防火墙开放以下端口 UDP 137 UDP 138 TCP 139 TCP 445 如果碰到 “Unable to save xxxxxxxx 拒绝访问” 的提示,还有最 ...
- Fiddler抓包8-打断点(bpu)【转载】
本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/fiddler/ 前言 先给大家讲一则小故事,在我们很小的时候是没有手机的,那时候跟女神 ...
- Jquery操作基本筛选过滤器
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- js中立即执行函数写法理解
在理解了一些函数基本概念后,回头看看( function(){…} )()和( function (){…} () )这两种立即执行函数的写法,最初我以为是一个括号包裹匿名函数, 并后面加个括号立即调 ...
- ios控件渐变色的处理
+(CAGradientLayer *)gradientColorWithBounds:(CGRect)bounds startColorHexString:(NSString *)startColo ...
- 使用keytool生成ssl证书
使用keytool生成ssl证书 在项目中由于要使用https访问项目,然后了解到jdk有一个自带的工具keytool可以用来生成ssl证书,从而可以通过https进行访问. 使用keytool生成s ...
- #423 Div2 D
#423 Div2 D 题意 构造一个 n 个节点的树,恰好有 k 个叶子节点 (叶子节点的定义是只与树上的某一个节点存在连边),要求任意两个叶子节点的距离的最大值最小,距离为两个节点间边的数量,输出 ...
- HDU 3966 Aragorn's Story(树链剖分)(线段树区间修改)
Aragorn's Story Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...