Click here to Skip to main content
15,886,799 members
Home / Discussions / C#
   

C#

 
GeneralRe: Testing methodologies Pin
Eddy Vluggen18-Feb-18 10:36
professionalEddy Vluggen18-Feb-18 10:36 
AnswerRe: Testing methodologies Pin
BillWoodruff18-Feb-18 9:50
professionalBillWoodruff18-Feb-18 9:50 
QuestionSale Invoice Pin
Member 1368352817-Feb-18 20:37
Member 1368352817-Feb-18 20:37 
AnswerRe: Sale Invoice Pin
Richard MacCutchan17-Feb-18 21:06
mveRichard MacCutchan17-Feb-18 21:06 
AnswerRe: Sale Invoice Pin
OriginalGriff17-Feb-18 22:42
mveOriginalGriff17-Feb-18 22:42 
QuestionTop Level Properties Pin
User9874317-Feb-18 16:26
professionalUser9874317-Feb-18 16:26 
AnswerRe: Top Level Properties Pin
Mycroft Holmes17-Feb-18 22:34
professionalMycroft Holmes17-Feb-18 22:34 
AnswerRe: Top Level Properties Pin
BillWoodruff17-Feb-18 23:36
professionalBillWoodruff17-Feb-18 23:36 
Some folks hate static anything; some folks hate the idea of a Class "floating" outside any NameSpace; pundits rail against both as "violations" of OOP.

.Net itself often glues a bunch of static methods in a Type definition, like with 'String.

But, fact is: .NET C# provides a facility to allow a Class to be declared outside any user-defined NameSpace and used as a repository accessible to all app entities (when declared 'static, of course). This "floating Class" will exist in the Global Application NameSpace.

Whether you should use this facility should be, imho, a result of your choice based on your knowledge of .NET facilities for saving state of the app, of the app's controls, of the data the app manages. And, possible threading issues if the app is multi-user.
Rick_Bishop wrote:
They aren't read only
you can make its contents read-only:
using System;
using System.IO;

public static class Globals
{
    public const Int32 MaxFormWidth = 1000;

    public static String SerializeFileName { set; get; } = @"Data.xml";

    static readonly String SerializeFolderPath = @"MyAppSavedData";

    public static string GetSerializeFilePath(string filename = "")
    {
        if (filename != "" && SerializeFileName != filename)
        {
            SerializeFileName = filename;
        }

        string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

        path = Path.Combine(path, SerializeFolderPath, SerializeFileName);

        if(IsValidPath(path)) return path;

        throw new FileLoadException($"{path} is not a valid file path");
    }

    static bool IsValidPath(string path)
    {
        // code omitted
    }
}
'MaxFormWidth is readonly, 'SerializeFileName is read/write, 'SerializeFolderPath is read-only.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12


modified 19-Feb-18 3:45am.

GeneralRe: Top Level Properties Pin
User9874318-Feb-18 6:56
professionalUser9874318-Feb-18 6:56 
GeneralRe: Top Level Properties Pin
BillWoodruff18-Feb-18 8:22
professionalBillWoodruff18-Feb-18 8:22 
GeneralRe: Top Level Properties Pin
User9874318-Feb-18 18:12
professionalUser9874318-Feb-18 18:12 
GeneralRe: Top Level Properties Pin
Mycroft Holmes18-Feb-18 13:14
professionalMycroft Holmes18-Feb-18 13:14 
GeneralRe: Top Level Properties Pin
Pete O'Hanlon18-Feb-18 21:32
mvePete O'Hanlon18-Feb-18 21:32 
GeneralRe: Top Level Properties Pin
BillWoodruff18-Feb-18 21:39
professionalBillWoodruff18-Feb-18 21:39 
QuestionHelp on Copy/Paste for DateTimePicker Pin
manju 315-Feb-18 21:09
manju 315-Feb-18 21:09 
AnswerRe: Help on Copy/Paste for DateTimePicker Pin
OriginalGriff15-Feb-18 21:45
mveOriginalGriff15-Feb-18 21:45 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
manju 315-Feb-18 22:29
manju 315-Feb-18 22:29 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
OriginalGriff15-Feb-18 23:13
mveOriginalGriff15-Feb-18 23:13 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
manju 316-Feb-18 0:12
manju 316-Feb-18 0:12 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
OriginalGriff16-Feb-18 0:46
mveOriginalGriff16-Feb-18 0:46 
SuggestionRe: Help on Copy/Paste for DateTimePicker Pin
Richard Deeming16-Feb-18 1:41
mveRichard Deeming16-Feb-18 1:41 
AnswerRe: Help on Copy/Paste for DateTimePicker Pin
Gerry Schmitz16-Feb-18 5:30
mveGerry Schmitz16-Feb-18 5:30 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
manju 318-Feb-18 22:05
manju 318-Feb-18 22:05 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
manju 318-Feb-18 23:21
manju 318-Feb-18 23:21 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
Gerry Schmitz19-Feb-18 6:20
mveGerry Schmitz19-Feb-18 6:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.