C # programming Study #1

Source: Internet
Author: User

When referencing, you need to add the REF keyword to the parameter and use

    •         static bool Addnum (ref int val)    //reference        {            ++val;            return true;        }

    • The concept of a parameter array, which can accept an array of that type, without limiting the size of the keyword params

    •         static int GetLength (params int[] vals)    //parameter array        {            int sum = 0;            foreach (int val in vals)            {                sum + = val;            }            return sum;        }

    • The concept of output parameters, similar to the parameter array, but can not be initialized when declaring

  •         static int MaxValue (int[] intarray, out int maxindex)  //output parameter        {            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: the declaration of a delegate is similar to a function, but without the body of the function, and the delegate keyword is used. The declaration of a delegate specifies a return type and a list of parameters
  •         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));        }
  • Specifies that the class is abstract, cannot be instantiated, can only inherit, and may have abstract members
  •     Abstract class MyClass1    {    }

  • Specifies that the class is a sealed sealed and cannot inherit
  •     Sealed class MyClass2    {    }

  • Member definitions
      1. Public members can be accessed by any code
      2. Private members are accessed by code in the class
      3. Internal members can only be accessed by code inside the assembly that defines it
      4. Protected members can only be accessed by code in a class or derived class
    • Defining methods
      1. The virtual method can override
      2. The abstract method must be overridden in a derived class of a non-abstract class
      3. The override method overrides a base class method
      4. The Extern method definition is placed elsewhere

C # programming Study #1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.