• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 566
  • Last Modified:

What is difference between Expression and Statement in terms of Programming Language (C#)

Hi Experts ,

I Some what confused what is difference between Expression and Statements in terms of all programming language . If its in C# it will be more clear for me and please explain in simple terms with examples will makes more Clear .

Thanks in Advance Experts
5 Solutions
Ryan ChongCommented:
would this help?

Statements, Expressions, and Operators (C# Programming Guide)
if (m > 10) (
   Console.Writeline("m is larger than 10");

In the above statement, the "(m > 10)" portion is an expression.

An expression is a part of a larger statement.
An expression is a any bit of code that results in a single answer
4+x (gives a number)
x > 5 (gives a true or a false)
log(x) + someFunctionYouWrote(x) != someOtherNumber (gives a true or false)

A statement is a block of code that changes something. The most simple (and mostly correct) way to explain it is any line that ends in a semicolon ; or block of code enclosed in { } (which C# calls a statement block)

x = 5 + y; //statement

if (x > 4)
   // do a bunch of single line statements in the statement block
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Pawan KumarDatabase ExpertCommented:
Expression --> Consider this as something which evaluates to a value, object, method, or namespace. It can be a literal value, a method invocation, an operator and its operands, or a simple name

((x < 10) && ( x > 5)) || ((x > 20) && (x < 25))  



Statement ---> Consider this as a line of code which does something. The actions that a program takes are expressed in statements. Common actions include declaring variables, assigning values, calling methods, looping through collections, and branching to one or another block of code, depending on a given condition. E.g.

int a;
a = 1;


Hope it helps.
I like simple clear answers, like:

Expression: Something which evaluates to a value, e.g.: x + y;
Statement: A line of code which does something, e.g.: myString.Trim();

A bit more elaborated answer from MSDN:

Expressions produce a result, which may or may not be used. 1+2 is an expression, just as it is in mathematics. Statement is short for expression statement, when some kind of expression exists within the statement. In C#, every statement ends with a semicolon. Each statement is, therefore, a complete line of code which may or may not include one or more expressions. For example, int i;  is a statement, not an expression statement as it contains no expressions - it is a simple declaration.

This may not be the most elaborate answer nor the most correct in the minds of those who know more programming history than me, but I would say it is accurate as far as C# is concerned.
karthik80cAuthor Commented:
Thanks Experts and am Clear now
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now