YoloJoeYolo
YoloJoeYolo
CC#
Created by YoloJoeYolo on 9/12/2023 in #help
Custom class is not able to be used with generic type T
Hello everyone I am just programming and run into a problem. I wrote a custom class:
namespace DMIS_API.Models
{
public class ServiceResponse<T>
{
public T? Data { get; set; }
public bool Success { get; set; } = true;
public string Message { get; set; } = string.Empty;
public int ErrorCode { get; set; } = 0;
}
}
namespace DMIS_API.Models
{
public class ServiceResponse<T>
{
public T? Data { get; set; }
public bool Success { get; set; } = true;
public string Message { get; set; } = string.Empty;
public int ErrorCode { get; set; } = 0;
}
}
However when I want to call it as a method parameter with generic type T it does not work: private void DoSomeThing(ref ServiceResponse<T> serviceResponse){...} it does not work. Can someone please help me?
15 replies
CC#
Created by YoloJoeYolo on 11/14/2022 in #help
❔ Change UDP Port
I've got a question. I'm working on a small GUI where I receive data by UDP. This already works fine. But I want to add the functionality to change the listening port. Here I struggle. Can some one help me?
public partial class Form1 : Form
{
private UdpClient udpClient;
private List<Measurment> measurments = new List<Measurment>();
private String serverIdentifier = "-temperature measurement system werner-";
private IPEndPoint receiveAdr;
private bool firtTimeReading = true;

private void btReadData_Click(object sender, EventArgs e)
{
if (firtTimeReading)
{
receiveAdr = new IPEndPoint(IPAddress.Any, int.Parse(this.nud_port.Value.ToString()));
udpClient = new UdpClient(receiveAdr);
this.ReceiveAsync();
firtTimeReading = false;
}
else
{
// Do something to change port to another value... here I need help
}
}

private async void ReceiveAsync() // async bedeutet, dass die Methode im Hintergrund ausgeführt wird
{
while (true)
{
UdpReceiveResult result = await udpClient.ReceiveAsync();
string value = Encoding.UTF8.GetString(result.Buffer);
...
}
}
public partial class Form1 : Form
{
private UdpClient udpClient;
private List<Measurment> measurments = new List<Measurment>();
private String serverIdentifier = "-temperature measurement system werner-";
private IPEndPoint receiveAdr;
private bool firtTimeReading = true;

private void btReadData_Click(object sender, EventArgs e)
{
if (firtTimeReading)
{
receiveAdr = new IPEndPoint(IPAddress.Any, int.Parse(this.nud_port.Value.ToString()));
udpClient = new UdpClient(receiveAdr);
this.ReceiveAsync();
firtTimeReading = false;
}
else
{
// Do something to change port to another value... here I need help
}
}

private async void ReceiveAsync() // async bedeutet, dass die Methode im Hintergrund ausgeführt wird
{
while (true)
{
UdpReceiveResult result = await udpClient.ReceiveAsync();
string value = Encoding.UTF8.GetString(result.Buffer);
...
}
}
2 replies