Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What is Best Method to Apply Business Rules to Properties in C# Class

Posted on 2012-04-04
1
Medium Priority
?
286 Views
Last Modified: 2012-04-09
I am attempting to write a new class that will be used by various users and other classes to display and save information. What would be the best way for these properties, which can be entered, calculated, and displayed to be accessed within a centralized C# class with rules on a specific business? I was looking for the easiest method to access them as other developers will be using the same code in the future. Any help would be greatly appreciated
0
Comment
Question by:thenthorn1010
1 Comment
 
LVL 1

Accepted Solution

by:
IceBird26 earned 2000 total points
ID: 37806382
You could use a static class that contains properties and methods which could be used without creating an instance of that class. An example:

public static class Global
{
    public const double Pie = 3.14159265;                           //Constant
    public static string ConnectionString = string.Empty;      //Property

    public static int AddNumbers(int x, int y)
    {
        return x + y;
    }
}


To use:

      static void Main()
      {
          int radius = 2;
          double circleArea = Global.Pie * radius * radius;

          Global.ConnectionString = "userid=jsmith; pwd=12345; server=Blueberry";
          MakeSQLConnection(Global.ConnectionString);

          int myTotal = Global.AddNumbers(5, 10);  
      }
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

877 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