Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 463375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:10:08+00:00 2026-05-12T23:10:08+00:00

I have been searching the web looking for a definition for declarative and imperative

  • 0

I have been searching the web looking for a definition for declarative and imperative programming that would shed some light for me. However, the language used at some of the resources that I have found is daunting – for instance at Wikipedia.
Does anyone have a real-world example that they could show me that might bring some perspective to this subject (perhaps in C#)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:10:09+00:00Added an answer on May 12, 2026 at 11:10 pm

    A great C# example of declarative vs. imperative programming is LINQ.

    With imperative programming, you tell the compiler what you want to happen, step by step.

    For example, let’s start with this collection, and choose the odd numbers:

    List<int> collection = new List<int> { 1, 2, 3, 4, 5 };
    

    With imperative programming, we’d step through this, and decide what we want:

    List<int> results = new List<int>();
    foreach(var num in collection)
    {
        if (num % 2 != 0)
              results.Add(num);
    }
    

    Here, we’re saying:

    1. Create a result collection
    2. Step through each number in the collection
    3. Check the number, if it’s odd, add it to the results

    With declarative programming, on the other hand, you write code that describes what you want, but not necessarily how to get it (declare your desired results, but not the step-by-step):

    var results = collection.Where( num => num % 2 != 0);
    

    Here, we’re saying “Give us everything where it’s odd”, not “Step through the collection. Check this item, if it’s odd, add it to a result collection.”

    In many cases, code will be a mixture of both designs, too, so it’s not always black-and-white.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching for the perfect web development IDE for some time now.
Have been looking at the MVC storefront and see that IQueryable is returned from
I have been searching on the web to see if I can use GoogleMaps
I have been searching all over the web trying to find an example of
I have been searching everywhere for the following functionality in Lisp, and have gotten
I have been searching high and low for a way to get my silverlight
I have been searching for info on this to no avail. The context of
I have been searching for a way to insert linebreaks in my code for
I have been experimenting with woopra.com A web analytics tool. Which requires a piece
I have been working on a web services related project for about the last

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.