Advertisement
Guest User

03.Форматиране на кода

a guest
Jan 7th, 2016
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. Форматиране на кода
  2. В C# при конструкции като if клаузата, след самата дума if има празно място и отварящата скоба е точно под първата буква на конструкцията. След отварящата скоба задължително има някакъв символ, т.е. няма празен ред или празно място)
  3. if (some condition)
  4. {
  5. }
  6.  
  7. for (int k = 0; k < 10; k++)
  8. {
  9. }
  10.  
  11. In Java, JavaScript
  12. if (some condition) {
  13. }
  14.  
  15. there is exactly one empty line after method declaration
  16.  
  17. there is exactly one blank space when we make a comment:
  18. // some comment
  19.  
  20.  
  21. Always use curly brackets (for if-clauses, for loops, etc.)
  22.  
  23. When we write methods they look like:
  24. In C#:
  25. There is no blank space between the name of the method and the opening bracket
  26. private static uint CalcFactorial(uint num,_int someNumber)
  27. {
  28. }
  29.  
  30. In JavaScript:
  31. function nameOfTheFunction(someVariable)_{
  32. }
  33.  
  34. When we call methods:
  35. In C#:
  36. RegisterUser(“nakov”, “password”);
  37. - there is no blank space between the name of the method and the opening bracket
  38.  
  39. in JavaScript:
  40. someFunction(“nakov”, “password”);
  41.  
  42.  
  43. Use an empty line to separate logically related sequences of lines of code.
  44.  
  45.  
  46. Order of definitions in classes, interfaces, structures:
  47. 1.constants
  48. 2.delegates
  49. 3.inner types (enums, inner classes)
  50. 4.fields
  51. 5.constructors
  52. 6.properties
  53. 7.methods
  54.  
  55. static members
  56. none static members:
  57. public members
  58. protected members
  59. internal members(available to be used only in the current project)
  60. private members
  61.  
  62. public class Dog
  63. {
  64. // Constants(static members)
  65. public const string Species = “Canis Lupus Familiaris”;
  66.  
  67. // Instance variables
  68. private int age;
  69.  
  70. // Constructors
  71. public Dog(string name, int age)
  72. {
  73. this.Name = name;
  74. this.age = age;
  75. }
  76.  
  77. // Properties
  78. public string Name { get; set; }
  79.  
  80. // Methods
  81. public void Breathe()
  82. {
  83. }
  84. }
  85.  
  86.  
  87. After the body of a construction(if-clause, for loop, etc.) there should be an empty line
  88.  
  89.  
  90. If-clauses:
  91. In C#:
  92. if (matrix[x, y] == 0 ||
  93. matrix[x – 1, y] == 0||
  94. matrix[x – 1, y - 1] == 0||
  95. matrix[x – 1, y] == 0)
  96. {
  97. }
  98.  
  99. In JavaScript(double tab):
  100. if (matrix[x, y] == 0 ||
  101. matrix[x – 1, y] == 0||
  102. matrix[x – 1, y - 1] == 0||
  103. matrix[x – 1, y] == 0) {
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement