
c#程序设计
文章平均质量分 65
夏天的波波
这个作者很懒,什么都没留下…
展开
-
c#简单题2
13.求n以内(不包括n)不能同时被2和5整除(能被2或者5整除但不能同时被整除)的所有自然数之和的平方根s,n从键盘输入。Console.WriteLine("请输入n"); int n = int.Parse(Console.ReadLine()); int sum = 0; for(int i=0;i<n;i++) { if(i%2!=0&&i%5!=原创 2021-01-02 11:19:01 · 928 阅读 · 0 评论 -
c#方法题1
回文是指顺读和倒读都一样的字符串。写一个方法,判断一个字符串str1,是否是回文,是回文返回true,否则返回false。例如字符串b是ag7ga是回文,而字符串abc6es就不是回文。要求编写应用程序,来检验方法的正确性。 private static bool huiwen(string s) { bool a; string str = null; for (int i = s.Length - 1; i >原创 2021-01-02 11:19:31 · 1774 阅读 · 2 评论 -
c#简单题.1
逆序输出 string s; Console.Write("请输入一个字符串:"); s = Console.ReadLine(); int i = s.Length; for (; i > 0; i--) { Console.Write(s[i - 1]); } Console.原创 2021-01-02 11:18:44 · 1925 阅读 · 0 评论 -
c#交换数,判断通过考试
static void Swap( ref int x, ref int y) { int temp; temp = x; x = y; y = temp; } int m = 2, n = 3; Console.WriteLine("交换前,两个数{0}和{1}",m,n); Swap(ref .原创 2020-12-05 18:10:10 · 110 阅读 · 0 评论 -
c#单词个数,加¥,最长单词,平均值
static int count(string sentence) { int count = 0; string[] words = new string[100]; words = sentence.Split(' '); for (int i = 0; i < words.Length; i++) { if (words[i]..原创 2020-11-28 16:20:26 · 228 阅读 · 0 评论 -
c#猫狗
class //Pet定义一个宠物类(Pet): { string name; //该类中定义私有的成员字段name姓名和age年龄,并设置其相应的公有属性; public string Name { get { return name; } set { name = value; } } int age; public int Age ..原创 2020-11-24 22:28:40 · 2022 阅读 · 0 评论 -
c#类设计题
class Worker//设计员工类(Worker)及其子类经理类(Manager),员工类包含私有字段name,salary; //并设置其属性Name,Salary;经理类还有自己的私有成员字段bonus,及其对应属性Bonus; { string name; public string Name { get { return name; } set { name = value; }.原创 2021-01-02 11:19:44 · 1808 阅读 · 0 评论 -
接口
接口自身可从多个接口继承 public interface Ia //接口Ia声明,接口修饰符可以是new、public、protected、internal和private,接口的命名建议以大写字母I开头 { void mymethod1(); } public interface Ib //接口Ib声明 { int mymethod2(int x); } public interface Ic : Ia, Ib //接口Ic从Ia和I原创 2020-11-24 21:24:33 · 240 阅读 · 0 评论 -
c#继承和接口设计 多态性
隐藏基类:法1-用新的派生成员替换基成员class A { public void fun() { Console.WriteLine("A"); } } class B : A { **new public void fun() //隐藏基类方法fun** { Conso原创 2020-11-19 10:46:11 · 381 阅读 · 0 评论 -
c#继承方法的使用
定义一个学生类(Student),有stuName私有字段及相应属性,有Disp方法,显示学生姓名;定义大学生类(CollegeStudent)继承基类Student,有Specialty公有字段和Practice方法,输出学生参与的项目名称;在主函数中实例化一个CollegeStudent的对象,并分别调用基类的方法和自身类的方法。//class Student { string stuName; public string StuName原创 2020-11-18 22:45:07 · 946 阅读 · 0 评论