1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+
5
+ namespace BadCodeProject
6
+ {
7
+ public class Program
8
+ {
9
+ public static void Main ( string [ ] args )
10
+ {
11
+ // Unused variable
12
+ int unusedVariable = 42 ;
13
+
14
+ // Redundant type specification
15
+ List < string > strings = new List < string > ( ) ;
16
+
17
+ // Possible null reference
18
+ string ? nullableString = null ;
19
+ Console . WriteLine ( nullableString . Length ) ;
20
+
21
+ // Inconsistent naming
22
+ int my_variable = 10 ;
23
+ int myVariable = 20 ;
24
+
25
+ // Unused parameter
26
+ void UnusedParameter ( int unusedParam )
27
+ {
28
+ Console . WriteLine ( "Hello" ) ;
29
+ }
30
+
31
+ // Redundant parentheses
32
+ int result = ( 1 + ( 2 * 3 ) ) ;
33
+
34
+ // Magic number
35
+ if ( result > 7 )
36
+ {
37
+ Console . WriteLine ( "Too high" ) ;
38
+ }
39
+
40
+ // Inconsistent string literal
41
+ Console . WriteLine ( "Hello" + " " + "World" ) ;
42
+
43
+ // Unnecessary boxing
44
+ object boxed = 42 ;
45
+
46
+ // Redundant ToString() call
47
+ string number = 42 . ToString ( ) ;
48
+
49
+ // Unused method
50
+ void UnusedMethod ( )
51
+ {
52
+ Console . WriteLine ( "Never called" ) ;
53
+ }
54
+
55
+ // Possible multiple enumeration
56
+ var numbers = Enumerable . Range ( 1 , 10 ) ;
57
+ var sum = numbers . Sum ( ) ;
58
+ var count = numbers . Count ( ) ;
59
+
60
+ // Inconsistent access modifiers
61
+ private int privateField = 0 ;
62
+ public int publicField = 0 ;
63
+
64
+ // Unnecessary cast
65
+ object obj = "string" ;
66
+ string str = ( string ) obj ;
67
+
68
+ // Redundant conditional
69
+ bool condition = true ;
70
+ if ( condition == true )
71
+ {
72
+ Console . WriteLine ( "Redundant" ) ;
73
+ }
74
+ }
75
+ }
76
+ }
0 commit comments