SoftwareEngineer666👿⸸⸸⸸
✅ Can't figure out json logic
once you get the hang of parsing json using DataContract it's really easy. Just play with it till you get the hang of it :). When you write a class and decorate properties with DataMember you have to remember to provide a set method too. It requires that even if you're serializing it. You can make the set method protected.
79 replies
Lambda expression and arrow function
Yes. If you want to parse lambda's around in C# you can either write a delegate or you can use built in Action and Func delegates. The last generic provided to Func is the return type. Action has no return type. So for example Action<string, int> theMethod = (aString, anInt)=>{ ...Do something}; Func<string, bool> = (stringIn)=>{ do something..... return true}; kinda thing. Or you could write a delegate public delegate bool MyDelegate(string aParameter, long anotherParameter); and use it like MyDelegate d = (aString, anotherParameter)=> { .... do something}. And you can miss off the curley brackets if you can write the function in a single line. If you want to use ref and out, you can do that if you write a delegate. But Action and Func wont let you do that.
4 replies
✅ Can't figure out json logic
namespace Chat.Messages.Client.Messages
{
[DataContract]
public class Example
{
[DataMember(Name = "username")]
public string Username { get; protected set; }
[DataMember(Name = "password")]
public string Password { get; protected set; }
}
}
79 replies