---
title: "Implement a function to reverse the order of words in a given sentence."  
description: "Implement a function to reverse the order of words in a given sentence."  
author: "Utpal Vishwas"  
published: 2023-06-14  
updated: 2023-06-15  
canonical: https://www.mindstick.com/forum/158747/implement-a-function-to-reverse-the-order-of-words-in-a-given-sentence  
category: "c#"  
tags: ["c#", "reverse", "programs"]  
reading_time: 1 minute  

---

# Implement a function to reverse the order of words in a given sentence.

Implement a [function to reverse](https://www.mindstick.com/forum/158799/write-a-rust-function-to-reverse-the-order-of-elements-in-a-vector) the [order of words](https://www.mindstick.com/forum/158763/implement-a-function-to-reverse-the-order-of-words-in-a-given-sentence-in-python) in a given sentence.

## Replies

### Reply by Aryan Kumar

Sure, here is a C# [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) to [reverse](https://www.mindstick.com/blog/63740/what-are-the-most-effective-and-safest-thanks-to-reverse-erectile-dysfunction) the [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) of words in a given sentence:

C#

```plaintext
public string ReverseWords(string sentence)
{
  // Split the sentence into words.
  var words = sentence.Split(' ');

  // Reverse the order of the words.
  var reversedWords = words.Reverse().ToArray();

  // Join the words back together into a sentence.
  return string.Join(" ", reversedWords);
}
```

This function first splits the sentence into words using the Split() method. It then reverses the order of the words using the Reverse() method. Finally, it joins the words back together into a sentence using the Join() method.

Here is an example of how to use the ReverseWords() function:

C#

```plaintext
string sentence = "This is a sentence.";

string reversedSentence = ReverseWords(sentence);

Console.WriteLine(reversedSentence);
```

This code will print the following output:

Code snippet

```plaintext
sentence is a This
```


---

Original Source: https://www.mindstick.com/forum/158747/implement-a-function-to-reverse-the-order-of-words-in-a-given-sentence

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
