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
Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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