Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Structured Programming in C#

Author: DevASP
Download Source Code : 525_UseStruct.zip

This article demonstrate that how we can create a structures in C#

Open visual studio and create a new .net application using C#. and drag Seven labels, Five combo boxes and a button on the from

And set the drop down style of combo box as drop down list

 

Now create a following structure

 

struct Std_Grade

            {          

                        public enum Rating {Poor, Average, Okay, Good, Excellent}

                        public enum Grading {A, B, C, D, F}

 

                        public string IntrotoC;

                        public string OS;

                        public string CLD;

                        public string Math;

                        public string Java;

                        public string Result;

                       

 

                        public Std_Grade (string ITC,string O,string C,string MA,string JA )

                        {

                                    IntrotoC = ITC;

                                    OS = O;

                                    CLD = C;

                                    Math = MA;

                                    Java = JA;

                                    Result = "";

                        }

                        public string GetGrade()

                        {

                                    if(IntrotoC == Grading.A.ToString() )

                                    {

                                                Result = "Result of Intro to C is " + Rating.Excellent.ToString()+"\n";

                                    }

                                    else if(IntrotoC == Grading.B.ToString() )

                                    {

                                                Result = "Result of Intro to C is " + Rating.Good.ToString()+"\n";

                                    }

                                    else if(IntrotoC == Grading.C.ToString() )

                                    {

                                                Result = "Result of Intro to C is " + Rating.Average.ToString()+"\n";

                                    }

                                    else if(IntrotoC == Grading.D.ToString() )

                                    {

                                                Result = "Result of Intro to C is " + Rating.Okay.ToString()+"\n";

                                    }

                                    else if(IntrotoC == Grading.F.ToString() )

                                    {

                                                Result = "Result of Intro to C is " + Rating.Poor.ToString()+"\n";

                                    }

                                    ///////////////////////

                                    if(OS == Grading.A.ToString() )

                                    {

                                                Result += "Result of OS  is " + Rating.Excellent.ToString()+"\n";

                                    }

                                    else if(OS == Grading.B.ToString() )

                                    {

                                                Result += "Result of OS  is " + Rating.Good.ToString()+"\n";

                                    }

                                    else if(OS == Grading.C.ToString() )

                                    {

                                                Result += "Result of OS is " + Rating.Average.ToString()+"\n";

                                    }

                                    else if(OS == Grading.D.ToString() )

                                    {

                                                Result += "Result of OS is " + Rating.Okay.ToString()+"\n";

                                    }

                                    else if(OS == Grading.F.ToString() )

                                    {

                                                Result += "Result of OS is " + Rating.Poor.ToString()+"\n";

                                    }

                                    /////////////////////////

                                    if(CLD == Grading.A.ToString() )

                                    {

                                                Result += "Result of CLD  is " + Rating.Excellent.ToString()+"\n";

                                    }

                                    else if(CLD == Grading.B.ToString() )

                                    {

                                                Result += "Result of CLD  is " + Rating.Good.ToString()+"\n";

                                    }

                                    else if(CLD == Grading.C.ToString() )

                                    {

                                                Result += "Result of CLD is " + Rating.Average.ToString()+"\n";

                                    }

                                    else if(CLD == Grading.D.ToString() )

                                    {

                                                Result += "Result of CLD is " + Rating.Okay.ToString()+"\n";

                                    }

                                    else if(CLD == Grading.F.ToString() )

                                    {

                                                Result += "Result of CLD is " + Rating.Poor.ToString()+"\n";

                                    }

                                    /////////////////////////

                                    if(Math == Grading.A.ToString() )

                                    {

                                                Result += "Result of Math  is " + Rating.Excellent.ToString()+"\n";

                                    }

                                    else if(Math == Grading.B.ToString() )

                                    {

                                                Result += "Result of Math  is " + Rating.Good.ToString()+"\n";

                                    }

                                    else if(Math == Grading.C.ToString() )

                                    {

                                                Result += "Result of Math is " + Rating.Average.ToString()+"\n";

                                    }

                                    else if(Math == Grading.D.ToString() )

                                    {

                                                Result += "Result of Math is " + Rating.Okay.ToString()+"\n";

                                    }

                                    else if(Math == Grading.F.ToString() )

                                    {

                                                Result += "Result of Math is " + Rating.Poor.ToString()+"\n";

                                    }

                                    /////////////////////////

                                    if(Java == Grading.A.ToString() )

                                    {

                                                Result += "Result of Java  is " + Rating.Excellent.ToString()+"\n";

                                    }

                                    else if(Java == Grading.B.ToString() )

                                    {

                                                Result += "Result of Java  is " + Rating.Good.ToString()+"\n";

                                    }

                                    else if(Java == Grading.C.ToString() )

                                    {

                                                Result += "Result of Java is " + Rating.Average.ToString()+"\n";

                                    }

                                    else if(Java == Grading.D.ToString() )

                                    {

                                                Result += "Result of Java is " + Rating.Okay.ToString()+"\n";

                                    }

                                    else if(Java == Grading.F.ToString() )

                                    {

                                                Result += "Result of Java is " + Rating.Poor.ToString()+"\n";

                                    }

 

                                    return Result;

                        }

            }

 

double click on from and write the following code on from load event

 

private void Form1_Load(object sender, System.EventArgs e)

{

            comboBox1.Text = "A";  

            comboBox2.Text = "A";  

            comboBox3.Text = "A";  

      comboBox4.Text = "A";  

comboBox5.Text = "A";  

}

 

Now double click on the button and write the following code button click event

 

private void button1_Click(object sender, System.EventArgs e)

{

 

Std_Grade s1 = new Std_Grade (comboBox1.Text,comboBox2. Text,comboBox3.Text,comboBox4.Text,comboBox5.Text);

label7.Text = s1.GetGrade();

 

}

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Add Fade-In and Fade-Out Effect to Your Windows Form

Disclaimer - Privacy
© 2002-2017 DevASP.net