1. C# / Говнокод #24486

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    static void MakeSubsets(char[] subset, int position = -1)
    {
    	/*if (position == subset.Length)
    	{
    		Console.WriteLine(new string(subset));
    		return;
    	}
    	subset[position] = 'a';
    	MakeSubsets(subset, position + 1);
    	subset[position] = 'b';
    	MakeSubsets(subset, position + 1);*/
    	
    	if(subset.Length == 0)
    	{
    		Console.WriteLine();
    		return;
    	}
    	
    	if(!(subset[0] >= 'a' && subset[0] <= 'z'))
    	{
    		for(int i = 0; i < subset.Length; ++i)
    			subset[i] = 'a';
    	}
    	
    	switch(subset.Length)
    	{
    		case 1:{ position = 0; }break;
    		default:{ position = position == -1 ? subset.Length - 2 : position; }break;
    	}
    	
    	Console.WriteLine(subset);
    	
    	//if(subset.Length <= 2)
    	//{
    	
    	if(subset[subset.Length - 1] + 1 != 'd')
    	{
    		++subset[subset.Length - 1];
    		MakeSubsets(subset,position);
    	}
    	else
    	{
    		switch(subset.Length)
    		{
    			case 1:
    				{
    					return;
    				}break;
    			default:
    				{
    					for(int i = position + 1; i < subset.Length; ++i)
    					{
    						subset[i] = 'a';
    					}
    					
    					if(subset[position] + 1 != 'd')
    					{
    						++subset[position];
    						MakeSubsets(subset,position);
    						return;
    					}
    					
    					bool bChange = false;
    					
    					while(true)
    					{
    						if(position < 0)
    						{
    							break;
    						}
    						if(subset[position] + 1 != 'd')
    						{
    							++subset[position];
    							bChange = true;
    							break;
    						}
    						subset[position] = 'a';
    						--position;
    					}
    					
    					if(bChange)
    					{
    						MakeSubsets(subset,-1);
    						return;
    					}
    					else
    						return;
    					
    				}break;
    		}
    	}
    	//}
    }
    //писал не индус

    Этот код выполняет ту же вещь(возвращает все комбинации с буквами a, b, c), что и этот код:


    static void MakeSubsets(char[] subset, int position = 0)
    {
    if (position == subset.Length)
    {
    Console.WriteLine(new string(subset));
    return;
    }
    for (char neww = 'a'; neww < 'd'; neww++)
    {
    subset[position] = neww;
    MakeSubsets(subset, position + 1);
    }
    }

    Verenick, 12 Июля 2018

    Комментарии (4)
  2. C# / Говнокод #24483

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    private void OutputLabels(DataTable dt)
    {
       string label; 
    
       // Iterate rows of table
       foreach (DataRow row in dt.Rows)
       {
          int labelLen;
          label = String.Empty;
          label += AddFieldValue(label, row, "Title");
          label += AddFieldValue(label, row, "FirstName");
          label += AddFieldValue(label, row, "MiddleInitial");
          label += AddFieldValue(label, row, "LastName");
          label += AddFieldValue(label, row, "Suffix");
          label += "\n";
          label += AddFieldValue(label, row, "Address1");
          label += AddFieldValue(label, row, "AptNo");
          label += "\n";
          labelLen = label.Length;
          label += AddFieldValue(label, row, "Address2");
          if (label.Length != labelLen)
             label += "\n";
          label += AddFieldValue(label, row, "City");
          label += AddFieldValue(label, row, "State");
          label += AddFieldValue(label, row, "Zip");
          Console.WriteLine(label);
          Console.WriteLine();
       }
    }
    
    private string AddFieldValue(string label, DataRow row, 
                                 string fieldName) 
    {                                
       if (! DBNull.Value.Equals(row[fieldName])) 
          return (string) row[fieldName] + " ";
       else
          return String.Empty;
    }

    label не используется в AddFieldValue. Официальный пример MS - https://docs.microsoft.com/en-us/dotnet/api/system.dbnull.value?view=netframework-4.7.2

    gogishvilli001, 12 Июля 2018

    Комментарии (90)
  3. C# / Говнокод #24477

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    while (reconnect)
    {
        ...
        reconnect = false;
        ...
    }

    gogishvilli001, 11 Июля 2018

    Комментарии (1)
  4. C# / Говнокод #24396

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    try 
    { 
    docdate = po.Items[0].ReqSendTransferList[0].TransferData[0].Payer[0].PaperCredentials[0].IssueDate; 
    } 
    catch 
    { 
    docdate = "01.01.1900"; 
    } 
    
    
    
    try 
    { 
    docwho = po.Items[0].ReqSendTransferList[0].TransferData[0].Payer[0].PaperCredentials[0].Issuer; 
    } 
    catch 
    { 
    docwho = ""; 
    } 
    
    try 
    { 
    dockod = po.Items[0].ReqSendTransferList[0].TransferData[0].Payer[0].PaperCredentials[0].IssuerCode; 
    } 
    catch 
    { 
    dockod = ""; 
    } 
    
    phone = po.Items[0].ReqSendTransferList[0].TransferData[0].Payer[0].Phone; 
    
    try 
    { 
    docser = po.Items[0].ReqSendTransferList[0].TransferData[0].Payer[0].PaperCredentials[0].SerialNumber; 
    } 
    catch 
    { 
    docser = ""; 
    } 
    
    try 
    { 
    docnom = po.Items[0].ReqSendTransferList[0].TransferData[0].Payer[0].PaperCredentials[0].CNumber; 
    } 
    catch 
    { 
    docnom = ""; 
    } 
    
    birthplace = ""; 
    try 
    { 
    birthplace = po.Items[0].ReqSendTransferList[0].TransferData[0].Payer[0].Registry[5].PValue.ToString().Trim(); 
    } 
    catch 
    { 
    birthplace = ""; 
    } 
    
    
    try 
    { 
    birthplace = birthplace + ", " + po.Items[0].ReqSendTransferList[0].TransferData[0].Payer[0].Registry[6].PValue.ToString().Trim(); 
    } 
    catch 
    { 
    s = ""; 
    }

    NullReference - нет, не слышал

    awesome3000, 20 Июня 2018

    Комментарии (4)
  5. C# / Говнокод #24278

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    public class Parameter
    {
      public string Name { get; }
      public int Value { get; }
    
      private Parameter(string name, int value)
      {
        Name = name;
        Value = value;
      }
    
      public static Func<int, Parameter> GetDeferredConstructor(string name)
      {
        return value => new Parameter(name, value);
      }
    }
    
    public class Program
    {
      public static void Main(string[] args)
      {
        var dc = Parameter.GetDeferredConstructor("param");
        var p = dc(5);
      }
    }

    mazhuravlev, 17 Мая 2018

    Комментарии (6)
  6. C# / Говнокод #24237

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public override bool IsViewFromObject(View view, Java.Lang.Object @object)
    		{
    			// actually... i don't know
    			return true;
    		}

    Прод код одного ведро-приложения, адаптер к листалке

    cherepets, 09 Мая 2018

    Комментарии (0)
  7. C# / Говнокод #24212

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    private static bool IsOnlyServiceWindowsFile(string directory)
    {
    	string[] ignoredFiles = { "Thumbs.db", "Desktop.ini" };
    	var files = Directory.GetFiles(directory);
    	foreach (var file in files)
    	{
    		var filename = Path.GetFileName(file);
    		foreach (var ignored in ignoredFiles)
    		{
    			if (string.Equals(filename, ignored, StringComparison.OrdinalIgnoreCase))
    			{
    				goto NEXT;
    			}
    		}
    		return false;
    		NEXT: ;
    	}
    	return true;
    }

    Пришёл в C# из Java, где есть замечательная фича под названием Label.
    В C# для вложенных циклов оказался лишь GOTO.
    Метод проверяет наличие в каталоге только сервисных файлов винды.

    brnovk, 01 Мая 2018

    Комментарии (8)
  8. C# / Говнокод #24197

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    using (var stream = File.Open(inFile, FileMode.Open))
    using (var reader = new StreamReader(stream))
    using (var csvReader = new CsvReader(reader, new Configuration
    {
    HeaderValidated = HeaderValidated,
    MissingFieldFound = null,
    PrepareHeaderForMatch = header =>
        CultureInfo.CurrentCulture.TextInfo.ToTitleCase(header)
    }))
    using (var outStream = File.Open(outFile, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
    using (var writer = new StreamWriter(outStream))
    using (var csvWriter = new CsvWriter(writer))

    mazhuravlev, 26 Апреля 2018

    Комментарии (43)
  9. C# / Говнокод #24189

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    public static class MyExtensions {
      private static Random _random = new Random(); 
      
      public static bool IsMnogo(this object value) {
        try {
          var n = double.Parse(value.ToString());
          return n > 9999999999;
        } catch {
          return true;
        }
      }
      
      public static bool IsDavno(this DateTime value) {
        return value < new DateTime(1900 + _random.Next(10, 90), 04, 17);
      }
    }

    mazhuravlev, 21 Апреля 2018

    Комментарии (4)
  10. C# / Говнокод #24090

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    namespace CarsKursova
    {
        public static class Car
        {
            public static int x1, x2, x3, x4, x5, x6, x7, x8, x9, x10,
                                x11, x12, x13, x14, x15, x16, x17, x18, x19, x20,
                                x21, x22, x23, x24, x25, x26, x27, x28, x29, x30,
                                x31, x32, x33, x34, x35, x36, x37, x38, x39, x40,
                                x41, x42, x43, x44, x45, x46, x47, x48, x49, x50,
                                x51, x52, x53, x54, x55, x56, x57, x58, x59, x60,
                                x61, x62, x63, x64, x65, x66, x67, x68, x69, x70,
                                x71, x72, x73, x74, x75, x76, x77, x78, x79, x80,
                                x81, x82, x83, x84,
                                y1, y2, y3, y4, y5, y6, y7, y8, y9, y10,
                                y11, y12, y13, y14, y15, y16, y17, y18, y19, y20,
                                y21, y22, y23, y24, y25, y26, y27, y28, y29, y30,
                                y31, y32, y33, y34, y35, y36, y37, y38, y39, y40,
                                y41, y42, y43, y44, y45, y46, y47, y48, y49, y50,
                                y51, y52, y53, y54, y55, y56, y57, y58, y59, y60,
                                y61, y62, y63, y64, y65, y66, y67, y68, y69, y70,
                                y71, y72, y73, y74, y75, y76, y77, y78, y79, y80,
                                y81, y82, y83, y84;
            public static string car = " ";
            public static bool game_over = false;
            public static bool fix = true;
            public static int score = 0;
            public static char[,] game_grond = new char[35, 29];
            public static char[,] game_gr = new char[35, 29];
    ....
    }
     public static void RisovPole()
            {
                p = Console.CursorTop;
                z = Console.CursorLeft;
                Console.ForegroundColor = ConsoleColor.Cyan;
                WriteAt("|*|", 29, 0);
                WriteAt("|*|", 29, 1);
                WriteAt("|*|", 29, 2);
                WriteAt("|*|", 29, 3);
                WriteAt("|*|", 29, 4);
                WriteAt("|*|", 29, 5);
                WriteAt("|*|", 29, 6);
                WriteAt("|*|", 29, 7);
                WriteAt("|*|", 29, 8);
                WriteAt("|*|", 29, 9);
                WriteAt("|*|", 29, 10);
                WriteAt("|*|", 29, 11);
                WriteAt("|*|", 29, 12);
                WriteAt("|*|", 29, 13);
                WriteAt("|*|", 29, 14);
                WriteAt("|*|", 29, 15);
                WriteAt("|*|", 29, 16);
                WriteAt("|*|", 29, 17);
                WriteAt("|*|", 29, 18);
                WriteAt("|*|", 29, 19);
                WriteAt("|*|", 29, 20);
                WriteAt("|*|", 29, 21);
                WriteAt("|*|", 29, 22);
                WriteAt("|*|", 29, 23);
                WriteAt("|*|", 29, 24);
                WriteAt("|*|", 29, 25);
                WriteAt("|*|", 29, 26);
                WriteAt("|*|", 29, 27);
                WriteAt("|*|", 29, 28);
                WriteAt("|*|", 29, 29);
                WriteAt("|*|", 29, 30);
                WriteAt("|*|", 29, 31);
                WriteAt("|*|", 29, 32);
                WriteAt("|*|", 29, 33);
                WriteAt("|*|", 29, 34);
                WriteAt("-----------------------------+*|", 0, 35);
                WriteAt("*******************************|", 0, 36);
                WriteAt("-------------------------------+\n\n\n\n\n\n\n\n\n\n\n", 0, 37);
                Console.ResetColor();
            }
    public static void carplins()
            {
                y1 = 27; x1 = 13; y22 = 31; x22 = 13;
                y2 = 27; x2 = 14; y23 = 31; x23 = 14;
                y3 = 27; x3 = 15; y24 = 31; x24 = 15;
                y4 = 28; x4 = 13; y25 = 32; x25 = 13;
                y5 = 28; x5 = 14; y26 = 32; x26 = 14;
                y6 = 28; x6 = 15; y27 = 32; x27 = 15;
     
                y7 = 29; x7 = 10; y28 = 33; x28 = 10;
                y8 = 29; x8 = 11; y29 = 33; x29 = 11;
                y9 = 29; x9 = 12; y30 = 33; x30 = 12;
                y10 = 29; x10 = 13; y31 = 33; x31 = 13;
                y11 = 29; x11 = 14; y32 = 33; x32 = 14;
                y12 = 29; x12 = 15; y33 = 33; x33 = 15;
                y13 = 29; x13 = 16; y34 = 33; x34 = 16;
                y14 = 29; x14 = 17; y35 = 33; x35 = 17;
                y15 = 29; x15 = 18; y36 = 33; x36 = 18;
     
                y16 = 30; x16 = 10; y37 = 34; x37 = 10;
                y17 = 30; x17 = 11; y38 = 34; x38 = 11;
                y18 = 30; x18 = 12; y39 = 34; x39 = 12;
                y19 = 30; x19 = 16; y40 = 34; x40 = 16;
                y20 = 30; x20 = 17; y41 = 34; x41 = 17;

    Тетрисные гонки в консоли.
    По ссылке - дермомонстр на 400 строк - http://www.cyberforum.ru/csharp-beginners/thread2169797.html

    ikekyourmom, 07 Апреля 2018

    Комментарии (2)