Solved

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

Posted on 2016-11-07
6
85 Views
Last Modified: 2016-11-07
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
0
Comment
Question by:karthik80c
6 Comments
 
LVL 50

Assisted Solution

by:Ryan Chong
Ryan Chong earned 62 total points
ID: 41877303
would this help?

Statements, Expressions, and Operators (C# Programming Guide)
https://msdn.microsoft.com/en-sg/library/ms173142.aspx
1
 
LVL 21

Assisted Solution

by:JesterToo
JesterToo earned 62 total points
ID: 41877314
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.
1
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 252 total points
ID: 41877373
An expression is a any bit of code that results in a single answer
Examples:
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)

Examples
x = 5 + y; //statement

if (x > 4)
{
   // do a bunch of single line statements in the statement block
}
1
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 28

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 62 total points
ID: 41877385
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))  

System.Convert.ToInt32("35")

https://msdn.microsoft.com/en-us/library/ms173144.aspx

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;

https://msdn.microsoft.com/en-us/library/ms173143.aspx

Hope it helps.
1
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 62 total points
ID: 41877738
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.
1
 

Author Closing Comment

by:karthik80c
ID: 41878157
Thanks Experts and am Clear now
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question! 4 36
Why does my excel data start at B1 instead of A1. 9 83
performance tune IIS 10 on win 2016 that only runs one website 4 62
C# bracket error 3 30
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

770 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