[Solved] Using curly braces like in constructor to set new values to a base object

Figured it out: public class MyClass { public MyClass() { } public MyClass(MyClass baseInstance) { var fields = typeof(MapObject).GetFields(); foreach (var field in fields) field.SetValue(this, field.GetValue(baseInstance)); var props = typeof(BaseItems).GetProperties(); foreach (var prop in props) if (prop.CanWrite) prop.SetValue(this, prop.GetValue(baseInstance)); } } … lets you do this: public static MyClass MyClass2 => new MyClass(MyClass1) { Property1 … Read more

[Solved] Converting string to float issue

If your string uses dot (.) as decimal separator, you should use this overload: float xFreq = Convert.ToSingle(param, CultureInfo.InvariantCulture); Not really sure, but Additional information looks Slavic to me and the default decimal separator might be comma (,) instead of dot. Of course, this depends on the culture of the current thread which depends on … Read more

[Solved] Want to ask the user what file they want to scan in C [closed]

#include <stdio.h> #include <stdlib.h> // You need to include the relevant headers // – stdio.h for printf, scanf etc // – stdlib.h for system int main(void) { char name[20]; printf(“Enter the file name: “); scanf(“%19s”, name); // Scan a string (word). Since the array size is 20, scan a // maximum of 19 characters (+1 … Read more

[Solved] multiple items price calculation in C

You need a variable total to add up the total cost. Your code will look like this: #include<stdio.h> int main() { char ch; int total=0; printf(“Which option will you choose:\n”); printf(“a) cpu 1 \n”); printf(“b) cpu 2 \n”); scanf(“%c”, &ch); switch (cpu) { case ‘a’: printf(“The price is 110 \n”); total+=110; break; case ‘b’: printf(“The … Read more

[Solved] String return from member function in C++

In C and C++ as opposed to C# and Java, variables do not need to be allocated in dynamic memory, which includes strings and character arrays. If you need or want to return pointers from a function, they must point to some variable that won’t disappear after execution leaves the function. The two popular techniques … Read more

[Solved] Using 2 thread to write in 2 text file with C# [closed]

you need to break the data into chunks. There are several algorithms for this, but I will demonstrate with “odd and even”. This help you? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { //odd Thread _th1 = new … Read more

[Solved] Why 2 and -2 instead of 1 and -1? [closed]

You need to understand the concepts of post increment(decrement) and pre increment(decrement). Post increment cout << x++<<endl; You can understand this line as “Return the value of x” + “increment the value of x”. I.e The return value is before the increment. So return 0 and increase the value of x to 1. Pre increment … Read more

[Solved] String Split with comma [duplicate]

Just use Split: string[] yourStrings = s.Split(‘,’); Actually, what I think you’re asking for is a return string like this: “red, blue, green, yellow” To achieve that, you need to use string.Join. Try this: public static string getcolours() { List<string> colours = new List<string>(); DBClass db = new DBClass(); DataTable allcolours = new DataTable(); allcolours … Read more

[Solved] Palidrome program is not workig [closed]

scanf(“%d%d%d%d%d”,&a,&b,&c,&d,&e,&f); You should have another %d there. Otherwise f contains a garbage value and it’ll be never equals a. I recommend you to reconsider your code and write something more general, like reading a string instead of individual ints. 3 solved Palidrome program is not workig [closed]

[Solved] New class object error : Object reference not set to an instance of an object [duplicate]

This is your problem: _cache.TryGetValue(“CountsStats”, out countStats) out will change the object that countStats is pointing to. If it’s found in the cache, then it will be the cached object. Great! If it isn’t, then it will be null. You need to create a new instance in this case. You should change your code to … Read more

[Solved] How to access an index in a vector without segfaulting

After std::vector<float> some_vec; your vector is empty. You must not access any element in it then, because there isn’t any. If you want to put values into it, you need to append them to the vector using push_back() for (some iterator loop here) { //snip some_vec.push_back(some_float); i++; } Alternatively, if you know the size in … Read more