Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-13
3
Medium Priority
?
391 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 375 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

688 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