1.传真  传址

namespace 传值_传址
{
class Program
{
//格式1:无参无返
public void LeiJia()
{
Console.Write("请输入一个正整数:");
int a = int.Parse(Console.ReadLine());
int sum = ;
for (int i = ; i <= a;i++ )
{
sum += i;
}
Console.WriteLine(sum);
} //格式2:有参无返
public void LeiJia(int zhengshu)
{
int sum = ;
for (int i = ; i <= zhengshu; i++)
{
sum += i;
}
Console.WriteLine(sum);
} //格式3:有参有返
public int LeiJia1(int zhengshu)
{
int sum = ;
for (int i = ; i <= zhengshu; i++)
{
sum += i;
}
return sum;
} //格式4:无参有返
public int Leijia2()
{
Console.Write("请输入一个正整数:");
int a = int.Parse(Console.ReadLine());
int sum = ;
for (int i = ; i <= a; i++)
{
sum += i;
}
return sum;
} //写个函数,传值进去,传姓名、性别、年龄进入
//将年龄+10岁
//反馈回来
public string Fanhui(string name , string sex,int age)
{
age += ;
return name + "-"+sex +"-"+ age;
} //传值
public void Hanshu(int a)
{
a += ; }
//传址
public void hanshu1(int a , out int b,out int c)
{
//int c = a + b;
b = a + ;
c = b; } public int AA = ; static void Main(string[] args)
{ //传值:将变量名中存放的值进行传输
//传址:将这个变量名直接传输过去,
//若在另一边有赋值情况,这边的值会发生变化 //调用函数之前需要先初始化该Class 类
Program hanshu = new Program();
//Console.Write("请输入一个正整数:");
//int a = int.Parse(Console.ReadLine());
//hanshu.Hanshu(a);
//Console.WriteLine(a);
hanshu.AA = ;
Console.WriteLine(hanshu.AA); int a = ;
int rr;
int tt;
hanshu.hanshu1(a,out rr,out tt);
Console.WriteLine(rr); //调用格式1
//hanshu.LeiJia();
//调用格式2
//hanshu.LeiJia(15);
//调用格式3
//int sum = hanshu.LeiJia1(12);
//Console.WriteLine(sum);
//调用格式4
//int sum = hanshu.Leijia2();
//Console.WriteLine(sum); //string s = hanshu.Fanhui("张三","男",33);
//string[] aa = s.Split('-');
//foreach(string q in aa)
//{
// Console.WriteLine(q);
//}

传真 传址

2.结构体
结构体:自定义类型    值类型
一组变量的组合
需要定义的位置   class里面   main函数外面
里面包含的变量可以是多种数据类型的

 namespace 结构体
{
class Program
{ struct Student
{
public int xuehao;
public string name;
public string sex;
public Score score;
} struct Score
{
public double yufen;
public double shufen;
public double yingfen;
} struct Shop
{
public string name;
public double price; public int shuliang;
} static void Main(string[] args)
{
//实例化结构体
//Student st = new Student();
//st.xuehao = 1001;
//st.name = "张三";
//st.sex = "男";
//st.score = 33; //Student st1 = new Student();
//st1.xuehao = 1002;
//st1.name = "李四";
//st1.sex = "女";
//st1.score = 44; //ArrayList al = new ArrayList();
//Console.Write("请输入班级人数:");
//int a = int.Parse(Console.ReadLine());
//for (int i = 0; i < a;i++ )
//{
// Student sst = new Student();
// Console.Write("请输入第{0}个学生的学号:",(i+1));
// sst.xuehao = int.Parse(Console.ReadLine()) ;
// Console.Write("请输入第{0}个学生的姓名:", (i + 1));
// sst.name = Console.ReadLine();
// Console.Write("请输入第{0}个学生的性别:", (i + 1));
// sst.sex = Console.ReadLine();
// Console.Write("请输入第{0}个学生的分数:", (i + 1));
// sst.score = double.Parse(Console.ReadLine());
// al.Add(sst);
//}
//Console.WriteLine("所有人员信息输入完毕!请按回车键开始打印!");
//Console.ReadLine(); //for (int i = 0; i < al.Count;i++ )
//{
// Student sst = (Student)al[i];
// Console.WriteLine("第{0}个学生的学号是:{1},姓名是{2},性别是{3},分数是{4}。",(i+1),sst.xuehao,sst.name,sst.sex,sst.score);
//} ////实例化
//Student st = new Student();
//st.score.yufen = 77;
//st.score.shufen = 88;
//st.score.yingfen = 99;

结构体

3.超市购物 例题 方法二

 Console.WriteLine("0.开始购买");
//Console.WriteLine("1.洗发水 15元");
//Console.WriteLine("2.牙刷 5元");
//Console.WriteLine("3.可口可乐 3元");
//Console.WriteLine("4.水杯 12元");
//Console.WriteLine("5.毛巾 6元");
Console.WriteLine("6.结算(退出)"); Console.Write("请输入号码:");
for (int i = ; i == ; )
{
int aa = int.Parse(Console.ReadLine());
if (aa == )
{ ArrayList al = new ArrayList();
int biao1 = ;
for (int j = ; j == ; )
{
bool biaocuo = true;
//string[] array = new string[3];
Shop array = new Shop();
Console.Clear();
if (al.Count > )
{
for (int k = ; k < al.Count; k++)
{
//string[] yigou = (string[])al[k];
Shop yigou = (Shop)al[k];
//Console.WriteLine("您选择了{0},单价为{1}元,数量为{2}。", yigou[0], yigou[1], yigou[2]);
Console.WriteLine("您选择了{0},单价为{1}元,数量为{2}。", yigou.name, yigou.price, yigou.shuliang);
}
}
Console.WriteLine("1.洗发水 15元");
Console.WriteLine("2.牙刷 5元");
Console.WriteLine("3.可口可乐 3元");
Console.WriteLine("4.水杯 12元");
Console.WriteLine("5.毛巾 6元");
Console.WriteLine("6.结算"); Console.Write("请输入选项:");
int aaa = int.Parse(Console.ReadLine());
switch (aaa)
{
case :
//array[0] = "洗发水";
//array[1] = "15";
array.name = "洗发水";
array.price = ;
biao1++;
Console.Write("您选择的是洗发水,请问您需要多少瓶?");
break;
case :
//array[0] = "牙刷";
//array[1] = "5";
array.name = "牙刷";
array.price = ;
biao1++;
Console.Write("您选择的是牙刷,请问您需要多少支?");
break;
case :
//array[0] = "可口可乐";
//array[1] = "3";
array.name = "可口可乐";
array.price = ;
biao1++;
Console.Write("您选择的是可口可乐,请问您需要多少瓶?");
break;
case :
//array[0] = "水杯";
//array[1] = "12";
array.name = "水杯";
array.price = ;
biao1++;
Console.Write("您选择的是水杯,请问您需要多少个?");
break;
case :
//array[0] = "毛巾";
//array[1] = "6";
array.name = "毛巾";
array.price = ;
biao1++;
Console.Write("您选择的是毛巾,请问您需要多少块?");
break;
case :
if (biao1 == )
{
Console.Clear();
Console.WriteLine("您什么也没有购买,您已经走出了超市。。。");
j = ;
i = ;
}
else
{
double zong = ;
for (int k = ; k < al.Count; k++)
{
//string[] yigou = (string[])al[k];
Shop yigou = (Shop)al[k];
//Console.WriteLine("您选择了{0},单价为{1}元,数量为{2},单品总价:{3}。", yigou[0], yigou[1], yigou[2], (int.Parse(yigou[1]) * int.Parse(yigou[2])));
Console.WriteLine("您选择了{0},单价为{1}元,数量为{2},单品总价:{3}。", yigou.name, yigou.price, yigou.shuliang, yigou.price*yigou.shuliang);
//zong += int.Parse(yigou[1]) * int.Parse(yigou[2]);
zong += yigou.price * yigou.shuliang;
}
Console.Write("总价:" + zong + "元。请缴费:");
double erjiao = ;
for (int l = ; l == ; )
{
double jiao = double.Parse(Console.ReadLine());
jiao += erjiao;
if (jiao >= zong)
{
Console.WriteLine("交易成功,交易时间为:" + DateTime.Now);
Console.WriteLine("找零:" + (jiao - zong) + "元。");
Console.WriteLine("谢谢惠顾!再见!");
l = ;
j = ;
i = ;
}
else
{
erjiao = jiao;
Console.Write("缴费金额不足,请继续缴费:");
}
}
}
break;
default:
Console.WriteLine("查无此商品!请按回车键继续选择商品!");
Console.ReadLine();
biaocuo = false;
break;
}
if (i == && j == && biaocuo == true)
{
//array[2] = Console.ReadLine();
array.shuliang = int.Parse(Console.ReadLine());
//Console.WriteLine("您选择了{0},单价为{1}元,数量为{2}。请按回车键继续购买!", array[0], array[1], array[2]);
Console.WriteLine("您选择了{0},单价为{1}元,数量为{2}。请按回车键继续购买!", array.name, array.price, array.shuliang);
al.Add(array);
Console.ReadLine();
}
}
}
else if (aa == )
{
Console.Clear();
Console.WriteLine("您什么也没有购买!您已走出超市。。。");
i = ;
}
else
{
Console.Write("输入有误!请重新输入:");
}
}

Anaylist方法

4.用结构体做

结构体中   输出时 与数组的区别   需要先取出再逐个打印

   namespace 结构体
{
class Program
{ struct Student
{
public int xuehao;
public string name;
public string sex;
public double score;
} //struct Student
//{
// public int xuehao;
// public string name;
// public string sex;
// public Score score;
//} //struct Score
//{
// public double yufen;
// public double shufen;
// public double yingfen;
//} //struct Shop
//{
// public string name;
// public double price;
// public int shuliang;
//} static void Main(string[] args)
{ ArrayList al = new ArrayList();
Console.Write("请输入班级人数:");
int a = int.Parse(Console.ReadLine());
for (int i = ; i < a; i++)
{
Student sst = new Student();
Console.Write("请输入第{0}个学生的学号:", (i + ));
sst.xuehao = int.Parse(Console.ReadLine());
Console.Write("请输入第{0}个学生的姓名:", (i + ));
sst.name = Console.ReadLine();
Console.Write("请输入第{0}个学生的性别:", (i + ));
sst.sex = Console.ReadLine();
Console.Write("请输入第{0}个学生的分数:", (i + ));
sst.score = double.Parse(Console.ReadLine());
al.Add(sst);
}
Console.WriteLine("所有人员信息输入完毕!请按回车键开始打印!");
Console.ReadLine(); for (int i = ; i < al.Count; i++)
{
Student sst = (Student)al[i];
Console.WriteLine("第{0}个学生的学号是:{1},姓名是{2},性别是{3},分数是{4}。", (i + ), sst.xuehao, sst.name, sst.sex, sst.score);
}

stract例题

结构体中 分数的 写法

 using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 周六_总复习
{
class Program
{
struct student
{
public string name;
public string xuehao;
public score score; //score 类 public score scaore; }
struct score
{
public double yuwen;
public double shuxue;
public double yingyu;
} static void Main(string[] args)
{ ArrayList cj = new ArrayList();
Console.WriteLine("输入班级人数");
int n = int.Parse(Console.ReadLine()); for (int i = ; i < n; i++)
{
student xx = new student();
Console.WriteLine("输第{0}个学生的姓名", (i + ));
xx.name = Console.ReadLine();
Console.WriteLine("输入第{0}个学生的学号", (i + ));
xx.xuehao = Console.ReadLine(); Console.WriteLine("输第{0}个学生的语文成绩", (i + ));
xx.score.yuwen = double.Parse(Console.ReadLine());
Console.WriteLine("输入第{0}个学生的数学成绩", (i + ));
xx.score.shuxue = double.Parse(Console.ReadLine());
Console.WriteLine("输入第{0}个学生的英语成绩", (i + ));
xx.score.yingyu = double.Parse(Console.ReadLine());
cj.Add(xx);
}
for (int i = ; i < n - ; i++)
{
for (int j = i + ; j < n; j++)
{
student q1 = (student)cj[i];
student q2 = (student)cj[j];
if (q1.score.yuwen < q2.score.yuwen)
{
object w;
w = cj[i];
cj[i] = cj[j];
cj[j] = w;
}
}
for (int q = ; q < n; q++) //打印与数组 打印的区别
{
student m = (student)cj[q];
Console.WriteLine("第{0}个学生名字:{1};学号:{2};语文成绩:{3};数学成绩:{4};英语成绩{5}", (i + ), m.name, m.xuehao, m.score.yuwen, m.score.shuxue, m.score.yingyu);
}
} Console.ReadLine(); }
}
}

数组 注意 struct里面 分数的写法

C#传真传址 结构体的更多相关文章

  1. C++结构体与Delphi结构体相互传参,结构体中包含结构体的嵌套,数组指针

    //结构体的声明 typedef struct Mwinddirectbaseline { char* p; int s; int i; }Mwinddirectbaseline; typedef s ...

  2. C#调用C++系列二:传结构体

    这一篇记录下C#调用C++的结构体的方式来使用OpenCV的数据格式,这里会有两种方式,第一种是C#传一个结构体和图像的路径给C++,然后C++将图像加载进来,再把传进来的结构体填满即可,第二种是C# ...

  3. 转载 C#结构体(struct)和类(class)的区别

    转载原地址: http://dotnet.9sssd.com/csbase/art/8 C#结构体和类的区别问题:在C#编程语言中,类属于引用类型的数据类型,结构体属于值类型的数据类型,这两种数据类型 ...

  4. C语言 结构体传值与传址分析

    /********************************************************************** * 版权所有 (C)2017, Wang maochun ...

  5. C#调用C++ dll时,结构体引用传参的方法

    写了一个C++的LogLog Logit 四参数等算法的接口dll,给C#调用,但是发现传参有问题 如 extern "C" _declspec(dllexport)  bool ...

  6. 将c语言的结构体定义变成对应的golang语言的结构体定义,并将golang语言结构体变量的指针传递给c语言,cast C struct to Go struct

    https://groups.google.com/forum/#!topic/golang-nuts/JkvR4dQy9t4 https://golang.org/misc/cgo/gmp/gmp. ...

  7. c/c++ 结构体传参问题

    c/c++的结构体传参可以有三种方式: 1.传递结构体变量,值传递 2.传递结构体指针,地址传递 3.传递结构体成员,可是值传递也可以是地址传递 根据代码示例: 1.传递结构体变量 #include& ...

  8. JNA 传参char[] 和结构体等

    近日项目中需要用java调用c/c++编写的dll库,所有了解到jna这个东东,下面是使用的一些经验: 一.java使用Jna需要两个jar包,eg:jna-3.5.1.jar和platform-3. ...

  9. 【Golang】创建有配置参数的结构体时,可选参数应该怎么传?

    写在前面的话 Golang中构建结构体的时候,需要通过可选参数方式创建,我们怎么样设计一个灵活的API来初始化结构体呢. 让我们通过如下的代码片段,一步一步说明基于可选参数模式的灵活 API 怎么设计 ...

随机推荐

  1. rose中设置组合

    1.在工具栏选择 "association" (关联).2.编辑role B 属性 open specital , role B detail ,multiplic(重数) 为1, ...

  2. NetBeans使用习惯:升级与保存配置

    如何升级:点击 netbeans 的升级更新 ,即可升级版本:不推荐官网下载进行安装,否则会出现,以前的旧版本8.0的目录和8.0.1目录,虽然它会自动检测到以前版本的配置,提示导入... 如何备份: ...

  3. 网站全面采用UTF-8方法

    先是概念的理解: Unicode/UCS的压缩形式--UTF8出现了,套用官方网站的首句话『UTF-8 stands for Unicode Transformation Format-8. It i ...

  4. IOS开发之----NSDictionary,JSON和XML互相转换

    本文永久地址为 http://www.cnblogs.com/ChenYilong/p/4044521.html,转载请注明出处.     -(void)test {     //XML文本范例   ...

  5. iOS: 如何正确的绘制1像素的线

    iOS 绘制1像素的线 一.Point Vs Pixel iOS中当我们使用Quartz,UIKit,CoreAnimation等框架时,所有的坐标系统采用Point来衡量.系统在实际渲染到设置时会帮 ...

  6. java中堆栈(stack)和堆(heap)(还在问静态变量放哪里,局部变量放哪里,静态区在哪里.....进来)

    (1)内存分配的策略 按照编译原理的观点,程序运行时的内存分配有三种策略,分别是静态的,栈式的,和堆式的. 静态存储分配是指在编译时就能确定每个数据目标在运行时刻的存储空间需求,因而在编 译时就可以给 ...

  7. Java 的printf(转)

    出处:http://blog.csdn.net/swandragon/article/details/4653600 public class TestPrintf{public static voi ...

  8. php中0," ",null和false的区别

    php中很多还不懂php中0,"",null和false之间的区别,这些区别有时会影响到数据判断的正确性和安全性,给程序的测试运行造成很多麻烦.先看一个例子: <? $str ...

  9. PYTHON 集合set 方法

    集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变成集合,就自动去重了 关系测试,测试两组数据之前的交集.差集.并集等关系 常用操作 a = set([1,2,3,4,3,4] ...

  10. Arlenmbx!!!!

    我无限制的以安逸为想法 其实生活的不安逸 我所做的事情和思路到底正不正确? 我失败了? 我做不到? 我尝试做到? 我可以做到! 我能做到 我做到了我已经做到了 难道想法和现实是有区别的吗 有理想只是空 ...