. NET Study notes----2015-07-08 (Basic review and Exercise 03)

Source: Internet
Author: User

1. Write a function that receives a string , converts the first letter in the string entered by the user into lowercase and returns ( name specification camel name ) Name S.substring (0,1) s.substring (1);

There is a shunliu point to complete the topic = =!

Camel name: Camel-case except for the first word, capitalize the first letter of the other word.

Pascal: Pascal capitalizes the first letter at the time of naming

Write a function , receive a string , converts the first letter in a user-entered string to a size and then returns (naming specification Pascal)

        Static voidMain (string[] args) {Console.WriteLine ("please input the content of the point freely"); stringstr =Console.ReadLine (); //string newstr = Conversionsize (str); //Console.WriteLine (NEWSTR); //Convert Uppercase//Console.WriteLine (Conversionsize (str)); //Convert lowercaseConsole.WriteLine (Conversionsizesmall (str));        Console.readkey (); }        /// <summary>        ///converts the first character of a string to uppercase/// </summary>        /// <param name= "S" >the string to convert</param>        /// <returns>return String</returns>        Static stringConversionsize (strings) {stringNewS = s.substring (0,1).            ToUpper (); S= NewS + s.substring (1); returns; }        /// <summary>        ///converts the first character of a string to lowercase/// </summary>        /// <param name= "S" >the string to convert</param>        /// <returns>return String</returns>        Static stringConversionsizesmall (strings) {stringNewS = s.substring (0,1).            ToLower (); S= NewS + s.substring (1); returns; }

2. Declare two variables: int n1 = ten, N2 = 20, two variables are required, and the last output N1 is 20,n2 . Extension (*): How to swap without using a third variable?

The legendary question of the classic face

N1 = N1-N2; N1 = -10,N2 = 20;

N2 = n1 + n2; N1 = -10,N2 = 10;

N1 = n2 + N1; N1 = 20; N2 = 30;

Successful exchange, suitable for any number

Ref: General ref is used to pass parameters.

To use the ref parameter, you must explicitly pass the parameter to the method as a ref parameter.
The value of the ref parameter is passed to the ref parameter. The arguments passed to the ref parameter must be initialized first.
Comparing this method to an out parameter, the latter's arguments do not have to be explicitly initialized before they are passed to the out parameter. property is not a variable and cannot be passed as a ref parameter.

        Static voidMain (string[] args) {            intN1 =3; intN2 =456; Swap (refN1,refn2); Console.WriteLine ("N1={0},n2={1}", N1, N2);        Console.readkey (); }        /// <summary>        ///Exchange values of 2 variables without using a third-party variable/// </summary>        Static voidSwap (ref intN1,ref intn2) {N1= N1-N2; N2= n1 +N2; N1= N2-N1; }

3. Ask the user to enter a string, count the number of characters in the string, and output.

 static  void  Main (string  [] args) {Console.WriteLine (  "  Please just enter something  "  );             string  str = Console.ReadLine (); Console.WriteLine (   The length of the string you entered is: {0}   , str.            Length);        Console.readkey (); }

4, using the method to achieve: Calculate the maximum value of two numbers. Thinking: The parameters of the method? return value? Extension (*): Calculates the maximum value between any number of numbers (hint:params).


To declare a method as a method that can accept a variable number of parameters, we can use the params keyword to declare an array, requiring:

(1) No additional parameters are allowed after the params keyword in the method declaration, and only one params keyword is allowed in the method declaration.

(2) This parameter must identify a one-dimensional array, but the type is not limited, and a reference to pass NULL or 0 number of arrays to that parameter is legal.

        Static voidMain (string[] args) {            int[] Nums = {1,2,3,4,5,6,7,8,9,Ten }; Console.WriteLine ("The maximum value is: {0}", MaxValue (nums));        Console.readkey (); }        /// <summary>        ///To find the maximum value/// </summary>        /// <param name= "Nums" >variable Array</param>        /// <returns>returns the maximum value</returns>        Static intMaxValue (params int[] nums) {            intMax =0;  for(inti =0; I < Nums. Length; i++)            {                if(Nums[i] >max) {Max=Nums[i]; }            }            returnMax; }

. NET Study notes----2015-07-08 (Basic review and Exercise 03)

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.