Advertisement
udaykumar1997

Untitled

Sep 1st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1.  
  2. ----
  3. 1. What is an Identifier? What's the syntax rule for Identifier?
  4. Ans. Identifiers are the names that you use to identify the elements in your programs, such as namespaces, classes, methods, and variables. In C#, you must adhere to the following syntax rules when choosing identifiers:
  5. - You can use only letters (uppercase and lowercase), digits, and underscore
  6. characters.
  7. - An identifier must start with a letter or an underscore.
  8. For example, result, _score, footballTeam, and plan9 are all valid identifiers, whereas result%, footballTeam$, and 9plan are not.
  9.  
  10. ----
  11. 2. What is a Variable? Write a note on variable naming Format. How to name a Variable?
  12. Ans. A variable is a storage location that holds a value. You use a variable’s name to refer to the value it holds.
  13.  
  14. Naming variables:
  15. You should adopt a naming convention for variables that helps you avoid confusion concerning the variables you have defined. The following list contains some general recommendations:
  16. - Don’t start an identifier with an underscore.
  17. - Don’t create identifiers that differ only by case.
  18. - Start the name with a lowercase letter.
  19. - In a multiword identifier, start the second and each subsequent word with an uppercase letter.
  20. - Don’t use Hungarian notation.
  21.  
  22. Declaring variables:
  23. Variables hold values. C# has many different types of values that it can store and process—integers, floating-point numbers, and strings of characters, to name three. When you declare a variable, you must specify the type of data it will hold. You declare the type and name of a variable in a declaration statement. For example, the statement that follows declares that the variable named age holds int (integer) values will look as follows :
  24. -
  25. int age;
  26. -
  27.  
  28. ----
  29. 3. What are the Primitive datatypes? Explain with Examples.
  30. Ans. C# has a number of built-in types called primitive data types. The following table lists the most commonly used primitive data types in C# and the range of values that you can store in each.
  31.  
  32. Table Link : http://bit.ly/2xCEHL2
  33.  
  34. ----
  35. 4. What are Airthematic Operators? Explain Operators and Types.
  36. Ans. C# supports regular arithmetic operations such as the plus sign (+) for addition, the minus sign (–) for subtraction. The symbols +, –, *, and / are called operators because they “operate” on values to create new values. In the following example, the variable 'mo' ends up holding the product of 750 and 20:
  37. -
  38. long mo;
  39. mo = 750 * 20;
  40. -
  41.  
  42. Operators and Types:
  43. Not all operators are applicable to all data types. The operators that you can use on a value depend on the value’s type. For example, you can use all the arithmetic operators on values of type char, int, long, float, double, or decimal. However, with the exception of the plus operator (+), you can’t use the arithmetic operators on values of type string, and you cannot use any of them with values of type bool.
  44.  
  45. ----
  46. 5. What is Controling Precedence? Explain Associativity to evaluate Exressions.
  47. Ans. Precedence governs the order in which an expression’s operators are evaluated. You can use parentheses to override precedence and force operands to bind to operators in a different way. For example, in the following expression, the parentheses force the 2 and the 3 to bind to the + operator (making 5), and the result of this addition forms the left operand of the * operator to produce the value 20:
  48. -
  49. (2 + 3) * 4
  50. -
  51.  
  52. Using associativity to evaluate expressions:
  53. Associativity is the direction (left or right) in which the operands of an operator are evaluated. Consider the following expression that uses the / and * operators:
  54. -
  55. 4 / 2 * 6
  56. -
  57. At first glance, this expression is potentially ambiguous. Do you perform the division first or the multiplication? The precedence of both operators is the same (they are both multiplicative), but the order in which the operators in the expression are applied is important because you can get two different results. In this case, the associativity of the operators determines how the expression is evaluated. The * and / operators are both left associative, which means that the operands are evaluated from left to right. In this case, 4/2 will be evaluated before multiplying by 6, giving the result 12.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement