01Net Foundation strengthens the first day-Foundation strengthening little exercises

Source: Internet
Author: User

`1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespacePractice18 {9     class ProgramTen     { One--------------------------------------------------------------------------------------- A #使用一般方式, Exchange values for two variables -        Static voidMain (string[] args) -         { the             #regionDeclaration of two variables: int n1=10, n2=20; Requires the exchange of two variables, the last output n1=20,n2=10, the extension (*): Do not use a third variable how to Exchange? -             intN1 =Ten, N2 = -; -       - #常规的交换数据方式 +             inttemp=N1; -n1=N2; +N2=temp; A      at #数学技术来交换数据方式 -N1 = n1 +N2; -N2 = N1-N2; -N1 = N1-N2; -  -Console.WriteLine ("n1="+N1);  inConsole.WriteLine ("n2="+n2); - Console.readkey (); to  +             #endregion -         } the------------------------------------------------------------------------------------ * #使用封装, to handle the value exchange of two variables \$         Static voidMain (string[] args)Panax Notoginseng         { -             #regionUse the method to achieve: encapsulate a method to do, the method has two parameters for num1,num2, the NUM1 and num2 Exchange. Hint: The method has two parameters N1, N2, in the method to exchange N1 with N2, using ref (*) the  +             intN1 =Ten, N2 = -; A  theSwap (refN1,refn2); +  -Console.WriteLine ("n1="+N1);  \$Console.WriteLine ("n2="+n2); \$ Console.readkey (); -  -             #endregion the         } - Wuyi         Private Static voidSwap (ref intN1,ref intn2) the         { -             //throw new NotImplementedException (); Wu             intTMP =N1; -N1 =N2; AboutN2 =tmp; \$         } --------------------------------------------------------------------------------------- -     } - } A     `

01Net Foundation strengthens the first day-Foundation strengthening little exercises

Related Keywords:
Related Article

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.