c# function

Posted on 2011-05-03
Last Modified: 2012-05-11

Can somebody explain to me what this function doing here please? as I don't know much about web development:

 private static object RequestObject
                object loRequestObject;

                if (HttpContext.Current != null &&
                    HttpContext.Current.Request != null)
                    loRequestObject = HttpContext.Current.Request;
                else if (WebOperationContext.Current != null &&
                    WebOperationContext.Current.IncomingRequest != null)
                    loRequestObject = WebOperationContext.Current.IncomingRequest;
                    loRequestObject = null;

                return loRequestObject;
Question by:ube100
    LVL 23

    Assisted Solution

    its not really a Function, its a READ ONLY PROPERTY.  a readonly properly almost does the same job as a RETURNS a value.

    Your Function basicly returns CURRENT Context(URL) of the Page/Service OR it reads the incoming data coming from different source.

    so loRequestObject  is of type Object. your function is returning an object of type HttpContext.Current.Request
     OR WebOperationContext.Current.IncomingRequest

    WebOperationContext.Current.IncomingRequest = A helper class that provides easy access to contextual properties of Web requests and responses.

    LVL 17

    Expert Comment

    by:Carlos Villegas
    Hi, it will return the available Request object based on the current context of your code.

    I meant, if it is called from an aspx page it will return HttpContext.Current.Request, but if it is called from another kind of application and HttpContext.Current.Request is not available then will try to return the WebOperationContext.Current.IncomingRequest, if not, return null.
    LVL 27

    Assisted Solution

    adilkhan - You're slightly off when you say: it's not really a function. On the contrary get and set accessors are ACTUALLY methods. Read my blog article below:

    ube100 - Your get accessor (or the get_RequestObject method, see my article) is actually trying to find the Request object in the context of a web application. It's trying to look at a couple of 'locations' to see if it can find a non-null request. In case it fails, it is returning null.

    From your question it seems to me that you happened to find this snippet of code and are trying to understand the concepts. My 2 cents is that you pick up an book and get a hold of the big-picture before getting into such nitty-gritty snippets.

    LVL 23

    Accepted Solution

    nmarun I totaly understand that, but if you read question carefully, poster asked what does this "function" do. I never used the word "Method" in my answer. Method could be either a function or Sub. and i also mention it does almost the same thing.

    I think it is our job to tell poster the difference. Properties are used basicly when you are creating a Class and you need to Set or a Return Value (eg; Item Attrbiutes etc). While function could be used within the Code file (anywhere).

    Properties are supposed to return value and the same value each time unless something else is called in between. A Method on the other hand is typically expected to do something in the background to get the value, or that the method may change the value each time it is called, like GetNextId() or something.

    So Technicaly if you are learning programming you cannot say Property and Method is Absolute SAME THING.

    LVL 17

    Expert Comment

    by:Carlos Villegas
    and I dont understand why that is too important, ube100 is just asking:

    Can somebody explain to me what this function (whatever, you get the idea) doing here please?
    I agreed with nmarun

    Author Closing Comment


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    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…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    729 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

    19 Experts available now in Live!

    Get 1:1 Help Now