Ошибка: Тип Chat уже определяет член с именем "Listen" с теми же типами параметров - C#

Узнай цену своей работы

Формулировка задачи:

Здравствуйте! Делаю чат на C#, но у меня выскакивает ошибка! Использую класс "Chat.cs":
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.Security.Cryptography;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ConsoleApplication2
  11. {
  12. class Chat
  13. {
  14. private UdpClient udpclient;
  15. private IPAddress multicastaddress;
  16. private IPEndPoint remoteep;
  17. public void SendOpenMessage(string data);
  18. public void Listen();
  19. public Chat()
  20. {
  21. multicastaddress = IPAddress.Parse("239.0.0.222"); // один из зарезервированных для локальных нужд UDP адресов
  22. udpclient = new UdpClient();
  23. udpclient.JoinMulticastGroup(multicastaddress);
  24. remoteep = new IPEndPoint(multicastaddress, 2222);
  25. }
  26. public void SendMessage(string data)
  27. {
  28. Byte[] buffer = Encoding.UTF8.GetBytes(data);
  29. Byte[] encrypted = Encrypt(data);
  30. udpclient.Send(buffer, buffer.Length, remoteep);
  31. udpclient.Send(encrypted, encrypted.Length, remoteep);
  32. }
  33. public void Listen()
  34. {
  35. UdpClient client = new UdpClient();
  36. client.ExclusiveAddressUse = false;
  37. IPEndPoint localEp = new IPEndPoint(IPAddress.Any, 2222);
  38. client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
  39. client.ExclusiveAddressUse = false;
  40. client.Client.Bind(localEp);
  41. client.JoinMulticastGroup(multicastaddress);
  42. Console.WriteLine("\tListening started");
  43. string formatted_data;
  44. while (true)
  45. {
  46. Byte[] data = client.Receive(ref localEp);
  47. formatted_data = Decrypt(data);
  48. formatted_data = Encoding.UTF8.GetString(data);
  49. Console.WriteLine(formatted_data);
  50. }
  51. }
  52. private byte[] Encrypt(string clearText, string EncryptionKey = "123")
  53. {
  54. byte[] clearBytes = Encoding.UTF8.GetBytes(clearText);
  55. byte[] encrypted;
  56. using (Aes encryptor = Aes.Create())
  57. {
  58. Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); // еще один плюс шарпа в наличие таких вот костылей.
  59. encryptor.Key = pdb.GetBytes(32);
  60. encryptor.IV = pdb.GetBytes(16);
  61. using (MemoryStream ms = new MemoryStream())
  62. {
  63. using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
  64. {
  65. cs.Write(clearBytes, 0, clearBytes.Length);
  66. cs.Close();
  67. }
  68. encrypted = ms.ToArray();
  69. }
  70. }
  71. return encrypted;
  72. }
  73. private string Decrypt(byte[] cipherBytes, string EncryptionKey = "123")
  74. {
  75. string cipherText = "";
  76. using (Aes encryptor = Aes.Create())
  77. {
  78. Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
  79. encryptor.Key = pdb.GetBytes(32);
  80. encryptor.IV = pdb.GetBytes(16);
  81. using (MemoryStream ms = new MemoryStream())
  82. {
  83. using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
  84. {
  85. cs.Write(cipherBytes, 0, cipherBytes.Length);
  86. cs.Close();
  87. }
  88. cipherText = Encoding.UTF8.GetString(ms.ToArray());
  89. }
  90. }
  91. return cipherText;
  92. }
  93. }
  94. }
А вот код мэйна:
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. namespace ConsoleApplication2
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Chat chat = new Chat();
  13. Thread ListenThread = new Thread(new ThreadStart(chat.Listen));
  14. ListenThread.Start();
  15. string data = Console.ReadLine();
  16. chat.SendMessage(data);
  17. }
  18. }
  19. }

Ошибка: Тип "ConsoleApplication2.Chat" уже определяет член с именем "Listen" с теми же типами параметров

Как решить эту проблему?

Решение задачи: «Ошибка: Тип Chat уже определяет член с именем "Listen" с теми же типами параметров»

textual
Листинг программы
  1.         public void SendOpenMessage(string data);
  2.         public void Listen();

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 3.625 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы