81-100 C# 电脑类程序
这还谈不上需求吧, 或者是最简单需求,基础功能的学会。yes,best 简单功能的学会以及熟练起来
电脑类文件
using System; using System.Collections.Generic; using System.Text; namespace 类的3大成员 { //类的成员:在类中能定义的元素,主要包括字段、属性、方法 public class Computer { // 1 字段定义 //public int price; //public string Nc; //public string Pmdx; // 自动属性设置 // 属性名 public double price { get; set; } // double类型,包含整数 public string Nc { get; set; } public string Pmdx { get; set; } // 2 定义方法输出指定字段的值 内容 public void Add_Print() { Console.WriteLine("电脑价格是:" + price); Console.WriteLine("电脑内存是:" + Nc); Console.WriteLine("电脑屏幕大小是:" + Pmdx); } } }
主函数调用
这个if is前端展示,就需要从Vue里面的JavaScript代码部分,去访问调用C#接口方法,通过访问接口方法去使用需要的值内容,这里仍然是练习,就是直接去主函数打印输出。
public class Program { public static void Main(string[] args) { #region 电脑类 Console.WriteLine("电脑类程序打印测试learn 练习"); // 先进行类的实例化,实例化一个对象 用对象去调用访问数据 方法 Computer context1= new Computer(); // 调用方法前,对属性赋值。 熟练后,可以从数据库里面去赋值,调用数据库里面的数据值内容。 // 为属性赋值 context1.price = 3350; context1.Nc = "10G"; context1.Pmdx = "14寸"; // 调用电脑类中的方法。 这里是对象点方面名字,直接调用的。 context1.Add_Print(); #endregion } }
打印效果