Solved

How to create OOP functionality e.g. x=MajorArea.SubAreas.SpecificMethod(Param1,Param2) etc

Posted on 2003-11-13
3
322 Views
Last Modified: 2010-04-16
I am new to C# and want to create very structured code where I am calling functions and retrieving information via nested processes. I would like each 'item' to be a seperate class file (e.g. class1.cs, class2.cs etc)

I am having difficulty grasping the concepts of C# including the 'using MyThing;' statements after using System.xxx, I know this exposes contents of namespaces but i cannot go any further then firstcall.secondcall

If you can implement the following into a C# code example I would be grateful:

A class called major.cs containing the following:
1) a static parameter I Get and Set e.g. string s=major.strSetting
2) a method which returns a value e.g. int i = major.AddThese(1,2)

Secondary classes called minor1.cs and minor2.cls which contain a method or two

An example of how I can call something like
MyResult = major.minor1.method1(1,2,3)

I am sure a good example of this will help other new users also.
0
Comment
Question by:nvms
3 Comments
 
LVL 6

Accepted Solution

by:
DaniPro earned 125 total points
ID: 9738664
I think that this examples is what you need:

using System;

namespace YourNs
{
      /// <summary>
      /// Descrizione di riepilogo per major.
      /// </summary>
      public class major
      {
            private static string _YourParameter;

            public major()
            {
                  //
                  // TODO: aggiungere qui la logica del costruttore
                  //
            }

            public static string YourParameter
            {
                  get
                  {
                        return _YourParameter;
                  }
                  set
                  {
                        _YourParameter = value;
                  }
            }

            public static int AddThese(int firstParm, int secondParm)
            {
                  return (firstParm + secondParm);
            }

            public class minor1
            {

                  public static int method1()
                  {
                        return 1;
                  }
            }

            public class minor2
            {

                  public static int method1()
                  {
                        return 2;
                  }
            }
      }
}
0
 
LVL 3

Expert Comment

by:Sijin
ID: 9738677
What you want can be done using nested classes, the only problem is that minor1 and minor2 cannot be in seperate class files, they have to be in the same file as major.

class Major
{

public staitc string strSetting=null;

public int AddThese(int a,int b)
{
return a+b;
}

    //This is an InnerClass
    public class Minor1
    {
         public static int method1(int a,int b,int c)
         {
               return 0;
          }
     }
}



0
 

Author Comment

by:nvms
ID: 9892396
Thanks, good advice
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now