Advertisement

Responsive Advertisement

V.3- Built-In Functions






 V.3- Built-In Functions

In C#, there are several built-in methods we can use with arrays. The full list can be found in the Microsoft documentation of the Array class, under methods.

SORT

The built-in method Array.Sort() (documentation), as its name suggests, sorts an array. This method is a quick way to further organize array data into a logical sequence:

1-Char FunctionC


2-String Function

3-Math Function

4-DateTime Function

V.4- VB Functions Equivalence in C#

The following table compares VBA functions with the similar VB.NET and C# functions and operators. The ActiveX library is indicated by “AutoCAD.Application” and the .NET Managed library equivalents are indicated by “Autodesk.AutoCAD” and the VB.NET or C# equivalents are listed as a function or operator.



Solution  Exercise:1

Source Code:

private void btnOK_Click(object sender, EventArgs e)

        {

            int N = int.Parse(txtValue.Text);

            int sum = 0;

            for (int i = 1; i<= N; i++)

            {

                sum += i;

            }

            txtResult.Text = sum.ToString();

        }

Result:1


Solution  Exercise:2

Source Code:

private void btnOK_Click(object sender, EventArgs e)

        {

            int N = int.Parse(txtValue.Text);

            int sum = 0;

            int i = 1;

            if (rptOdd.Checked == true)

            {

                while (i < N)

                {

                    if ((i % 2) != 0)

                        sum += i;

                    i++;

                }

            }

            else

            {

                while (i <= N)

                {

                    if ((i % 2) == 0)

                        sum += i;

                    i++;

                }

            }

            txtResult.Text = sum.ToString();

        }


Result:2

Solution  Exercise:3

Source Code:

private void btnMatch_Click(object sender, EventArgs e)

        {

            string stMath = "";

            

            for (char ch = 'a'; ch <= 'z'; ch++)

            {

                int x = (int)ch;

                if (x < 101)

                    stMath += ch + "=" + x.ToString() + "";

 

            }

            for (char ch = 'A'; ch <= 'Z'; ch++)

            {

                int x = (int)ch;

                if (x <101)

                    stMath += ch + "=" + x.ToString() + "";

            }

            txtMatch.Text = stMath;

 

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            string st = "";

            //add number to txtNumber

            for (int i = 1; i <= 100; i++)

                st += i.ToString() + " ";

            txtNumber.Text = st;

 

            //add letter tp txtLetter

            st = "";

            for (char ch = 'a'; ch <= 'z'; ch++)

                st += ch + "";

 

            for (char ch = 'A'; ch <= 'Z'; ch++)

                st += ch + "";

 

            txtLetter.Text = st;

        }

 

        private void btnunMatch_Click(object sender, EventArgs e)

        {

            string stUnmath = "";

 

            for (char ch = 'a'; ch <= 'z'; ch++)

            {

                int x = (int)ch;

                if (x > 100)

                    stUnmath += ch + "";

            }

            for (char ch = 'A'; ch <= 'Z'; ch++)

            {

                int x = (int)ch;

                if (x > 100)

                    stUnmath += ch + "";

            }

            txtUnmatch.Text = stUnmath;

        }




Result:3



Post a Comment

0 Comments