[Solved] Accessing a public class member dynamically

[ad_1] Try this: public class Names { public string Name1 { get; set; } public string Name2 { get; set; } public string Name3 { get; set; } } for (int i = 1; i <= collection.Count(); i++) { var col = collection.ElementAt(i); col.GetType().GetProperty(“Name + i”).SetValue(col, longString.Substring(11, 4), null); } Name1, Name2 and Name3 are … Read more

[Solved] C++ vector of struct allocated on stack

[ad_1] There are some options you can use. The first and easiest one, is to define a value to each (or for one) of your struct’s variables, that will point that the struct is not initialized yet. In this case, age should be large or equal to 0, to be logicly straight. So, you can … Read more

[Solved] Declare “Nullable[]” or “string[]?” for string array property that may or may not exist inside a class?

[ad_1] In short: you don’t need Nullable<T> or ? in this case at all. string[] is reference type: Console.WriteLine(typeof(string[]).IsValueType); the printed output will be false. So, it can be null without any decoration. Back to your sample. You need to specify setters as well to be able deserialize the given json fragement: public class Settings … Read more

[Solved] I want to covert julian date(YYJJJ format) to any normal date format(MMDDYY) using c#. Is there any defined function for that?

[ad_1] First of all, there is no YY, JJJ and DD formats as a custom date and time format. One solution might be to split your string Year and DayOfYear part and create a DateTime with JulianCalendar class. string s = “05365”; int year = Convert.ToInt32(s.Substring(0, 2)); // Get year part from your string int … Read more

[Solved] how to use the keys F1 to F10 in C code

[ad_1] For Windows, there is the _getch function, which returns the bytes of a key code, one by one. You can get a function key that way, detecting it by the presence of certain codes: 0x00 or 0xe0 as shown in the example in [C\C++] – how get arrow keys(correctly) using getch()?. When _getch returns … Read more

[Solved] How do you populate two Lists with one text file based on an attribute? [closed]

[ad_1] By the suggestions in the comments, partialy @Charles_May ‘s: Simply looping: List<string> Source = {}; //source list List<string> Females = new List<string>(), Males = new List<string>(); foreach (string value in Source) { if (value.ToUpper().Contains(“,F,”)) //Female { Females.Add(value); } else { Males.Add(value); } }//result: both lists are with values That’s it. if you’s like to … Read more

[Solved] How To Call Function Which Contains Parameter In Any Other Function Of Other Script?

[ad_1] You should use GetComponent<“ScriptName”>.StartGrab(), in which ScriptName is the name of the script that contains StartGrab(). Note that as your method has 3 parameters, when you call it, you should pass them, or else you’re gonna get compiler errors. For example: GetComponent<“ScriptName”>.StartGrab(objectToGrab, grabbedObject, objectController); You are now correctly calling the method. Note that objectToGrab, … Read more

[Solved] How to convert a math expression into sums of factors programmatically? [closed]

[ad_1] I found the shortest way to do this using Math.NET Symbolics from Math.NET The key syntax to do so is like this: SymbolicExpression.Parse(“a*(b+c)”).Expand().Summands().Select(x => x.Factors()); In it, I expand the expression and then I get the summands. For each of the summands, I get the factors. To illustrate it better, consider the following expression: … Read more

[Solved] Realloc to structure in c

[ad_1] You access out of bound for firma. data = (Order*)malloc(ordersize * sizeof(Order));//we allocte memory for the struct Order with pointer data add_orders(data, &ordersize); //send it As you allocated memory of size orderSize and you access firma[newstart]. newstart = *ordersize; //we just did it (*ordersize)++; // now we have new size +1 for the one … Read more

[Solved] No More Confusing Pointers

[ad_1] Point 1: Nested functions are not standard C. They are supported as GCC extension.. Point 2: printf(“&b is:%s\n”,&b); is wrong and invokes UB, because of improper format specifier. You need to change that to printf(“&b is:%p\n”,(void *)&b); Point 3: &(&a) is wrong. the operand for & needs to be an lvalue, not another address, … Read more