Solved

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

Posted on 2003-11-13
3
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…

734 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