Skip to main content

Posts

Showing posts from November, 2019

Expression and Statement in C#

Difference between statement and expression In programming language terminology, an “expression” is a combination of values and functions that are combined and interpreted by the compiler to create a new value, as opposed to a “statement” which is just a standalone unit of execution and doesn’t return anything.  C# Expressions An expression in C# is a combination of operands (variables, literals, method calls) and operators that can be evaluated to a single value. To be precise, an expression must have at least one operand but may not have any operator. Let's look at the example below: float price; price = 42.05; Here,  42.05  is an expression. Also,  price  = 42.05   is an expression too. int x, y, z, sum; sum = x + y + z; Here, x  + y + z  is an expression. if (age>=18 && age<58) Console.WriteLine("Eligible to work"); Here,  (age>=18 && age<58)  is an expression that returns a...

C# statements

Statement in c# is line of code that ends with a semi colon which does something. Eg Assignment var a=2; var b=3; var c=a+b; // arithmetic expression Logical If (a <b)  return a; C# statements are made up of keywords, expressions and operators which end a semi colon.