Solved

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

Posted on 2012-04-04
1
234 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 500 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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!
This video discusses moving either the default database or any database to a new volume.
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.

705 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

17 Experts available now in Live!

Get 1:1 Help Now