Solved

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

Posted on 2003-11-13
3
313 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

15 Experts available now in Live!

Get 1:1 Help Now