What's the problem of these codes or better way to write it

Posted on 2012-09-12
Last Modified: 2012-09-13
hi All,

here is the code review question i got it

1.      What is wrong with this statement?

       public static ulong SecondsInADay = 86399;

2.      What is wrong with the first line of this method (I’ve changed some of the names etc., so it’s not bad naming convention)?

       public static Response DoStuff(ADUser user)
                string search = "(cn=" + + ")";


3.      What would be a better way of doing this?

        public static string GetDomain()
            return "";

Thanks in Advance
Question by:Sha1395
    LVL 43

    Expert Comment

    >>here is the code review question i got it

    Is this homework?  (We can't answer for you, we could help you to correct things you say howver).

    Author Comment

    AndyAinscow, its not a home work anyway, just try to figure out the expert answers.
    LVL 43

    Expert Comment

    The first statement is just incorrect.  (Either the name is misleading or it is correct but the value given is wrong).  (Also have variables as public is not recommended - use get/set - and it is probably is meant to be a const).

    The second and third use hard coded values (BUT that might not be a problem).

    In general only use static when it is really required.  (If you don't understand what static does then look in the help files, it has a rather special effect.)
    LVL 8

    Assisted Solution

    Your first code is not CLS compliant.

    In the second case, you are risking an NullReferenceException, as might be null, and the call to Tream() will fail.

    I don't understand the las one.. But to get current domain, the right way is:

    Best regards.
    LVL 74

    Accepted Solution

    In general only use static when it is really required.
    I have come to learn that there are varying schools of thought on the usage of static. One of those schools says to use static whenever there is no reason to maintain state (something classes excel at doing). In that case, the method would satisfy that requirement assuming the "..." doesn't maintain any sort of state.

    What would be a better way of doing this?
    I might do a readonly property:


    public string Domain
        get { return ""; }

    Open in new window

    LVL 43

    Expert Comment

    Don't forget if the name in the first code segment is correct then number of seconds in a day is 24x60x60 which is NOT 86399

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now