C# Programming Study #1

引用的时候需要在参数和使用的时候加上 ref 关键字

  •         static bool addnum (ref int val)    //引用
            {
                ++val;
                return true;
            }
    
  • 参数数组的概念,可以接受该类型的数组,不限制大小,关键字 params
  •         static int getlength (params int[] vals)    //参数数组
            {
                int sum = 0;
                foreach (int val in vals)
                {
                    sum += val;
                }
                return sum;
            }
    
  • 输出参数的概念,类似参数数组,不过声明的时候可以不初始化
  •         static int MaxValue (int[] intArray, out int maxIndex)  //输出参数
            {
                int maxValue = intArray[0];
                maxIndex = 0;
                for (int i = 1; i < intArray.Length; ++i)
                {
                    if (intArray[i] > maxValue)
                    {
                        maxValue = intArray[i];
                        maxIndex = i;
                    }
                }
                return maxValue;
            }
    
  • 委托 delegate : 委托的声明类似函数,但不带函数体,并且要使用 delegate 关键字。委托的声明指定了一个 返回类型 和一个 参数列表
  •         delegate double ProcessDelegate (double param1, double param2);
    
            static double Multiply (double param1, double param2)
            {
                return param1 * param2;
            }
    
            static double Divide (double param1, double param2)
            {
                return param1 / param2;
            }
    
            static void Main(string[] args)
            {
                ProcessDelegate process;
                string input = Console.ReadLine();
                if (input.CompareTo("M") == 0)
                {
                    process = new ProcessDelegate (Multiply);
                }
                else
                {
                    process = new ProcessDelegate(Divide);
                }
                double param1 = 3.123;
                double param2 = 23.12;
                Console.WriteLine("{0}", process(param1, param2));
            }
    
  • 指定类是抽象的 abstract,不能实例化,只能继承,可以有抽象成员
  •     abstract class MyClass1
        {
    
        }
    
  • 指定类是密封的 sealed, 不能继承
  •     sealed class MyClass2
        {
    
        }
    
  • 成员定义
    1. public     成员可以由任何代码访问
    2. private       成员由类中的代码访问
    3. internal  成员只能由定义它的程序集内部的代码访问
    4. protected   成员只能由类或派生类中的代码访问
  • 定义方法
    1. virtual     方法可以重写
    2. abstract   方法必须在非抽象类的派生类中重写
    3. override   方法重写了一个基类方法
    4. extern      方法定义放在其他地方
时间: 2024-10-11 09:07:51

C# Programming Study #1的相关文章

C# Programming Study #2

readonly (C# Reference) readonly  关键字是可以在字段上使用的修饰符.  当字段声明包括 readonly 修饰符时,该声明引入的字段赋值只能作为声明的一部分出现,或者出现在同一类的构造函数中 class Age { readonly int _year; Age(int year) { _year = year; } void ChangeYear() { //_year = 1967; // Compile error if uncommented. } }

Beginning Scala study note(4) Functional Programming in Scala

1. Functional programming treats computation as the evaluation of mathematical and avoids state and mutable data. Scala encourages an expression-oriented programming(EOP) 1) In expression-oriented programming every statement is an expression. A state

study notes: high performance linux server programming

1:linux网络API分为:socker地址API,socker基础API,网络信息API 1,socker地址API:包含IP地址和端口(ip, port).表示TCP通信的一端. 2,socker基础API:创建/命名/监听socker,接收/发起链接,读写数据,获取地址信息,检测带外标记和读取/设置socker选项.sys/socket.h 3,网络信息API:主机名和IP地址的转换,服务名和端口号的转换.netdb.h 2:socket和API的函数 和 相关知识. 1,函数. 1 I

Dynamic Programming

We began our study of algorithmic techniques with greedy algorithms, which in some sense form the most natural approach to algorithm design. Faced with a new computational problem, we've seen that it's not hard to propose multiple possible greedy alg

Book Review of “The practice of programming” (Ⅳ)

The practice of programming Chapter 4 Interfaces A good programmer should always be good at designing. The essence of design is to balance competing goals and constraints. When we do programming, we need to design a friendly, portable and flexible in

The beginning iOS8 Programming with Swift 中文翻译 - 2

Audience 读者说 This book is written for beginners without any prior programming experience and those   这本书是写给那些想要学习swift语言但之前没有过任何开发经验的初学者 who want to learn Swift programming. Whether you are a programmer who wants to learn   无论你是想学习一门新的语言的程序员或者是一个想把自己

分享:Foundations of Python Network Programming(3rd) 英文版pdf 下载

Foundations of Python Network Programming Third Edition 下载http://www.amazon.com/Foundations-Python-Network-Programming-Brandon/dp/1430258543这本书是2014年底出版的,基于最新的 python3.4 版本.配书源码链接https://github.com/brandon-rhodes/fopnp 目录 Chapter 1: Introduction to C

Mooc论文【Why is it so hard to learn programming?】

Why is it so hard to learn programming? "Oh, programming is so hard!", many friends said like that to me. But, does programming is as hard as they think? The answer is No. In my opinion, programmer is similar to the pianist. Because, we both wor

Get your Advanced Java Programming Degree with these Tutorials and Courses

Getting started as a Java developer these days is quite straightforward. There are countless books on the subject, and of course an abundance of online material to study. 最近,入门成为一名java开发人员是非常简单的.有无相关的书籍,当然还有大量的在线资料可供学习 Of course, our own site offers