[Solved] Console App error An object reference is required for the non-static field, method, or property

I agree with the other commentors- what’s really missing here is an understanding of what the static keyword means and what it means to instantiate objects. The specific issue here is that your Program class’s fields requires an instance before they can be accessed (Program and it’s fields are not static) while your Main method … Read more

[Solved] Convert VB to C# ‘GetCustomAttribute’

You just have to cast to MessageHandler: InstanceType = (MessageHandler)System.Attribute.GetCustomAttribute(Method, typeof(MessageHandler), false); The clue is in this part of the error message: An explicit conversion exists (is a cast missing?) 0 solved Convert VB to C# ‘GetCustomAttribute’

[Solved] Replacing sub-string of a String with another String in c

The sprintf command has the following declaration: sprintf(char *str, const char *format, …); your declaration in question is: sprintf(buffer+(p-str), “%s%s”, rep, p+strlen(orig)); The sprintf command writes to the character pointer str, the values rep and p+strlen(orig) in accordance with the format string “%s%s”. Essentially, it is simply combining (or concatenating) rep and p+strlen(orig) in buffer+(p-str). … Read more

[Solved] C++ code not compiled correctly [closed]

First things first, cin << AmerAge; should be: cin >> AmerAge; I remember this with the memory aid: you input data to the variable, cin >> var, you output it from it, cout << var. Secondly, conio is not a C++ header, it’s not even a C header. It’s a blast from the past from … Read more

[Solved] Exit app on double tap (android app)

in c# void Update(){ if (Input.GetKeyDown(KeyCode.Escape)) Application.Quit(); } or in .js function Update(){ if (Input.GetKeyDown(KeyCode.Escape)) Application.Quit(); } This is the function for exit app when back button pressed, if you want to exit the app when back button pressed twice, implement the logic in the java code you have posted in question into equivalent code … Read more

[Solved] Arrays cannot be half of a number [closed]

Your understanding is correct: 8.3.4 Arrays In a declaration T D where D has the form D1 [constant-expression opt ] and the type of the identifier in the declaration T D1 is “derived-declarator-type-list T,” then the type of the identifier of D is an array type. T is called the array element type; this type … Read more

[Solved] Quicksort input text C++

Maybe you need to learn File I/O with C++. Basically you include <fstream> and create instances of fstream (for I/O), ifstream (for input only) or ofstream (for output only). Then you open a file and use the object as you usually do with cin/cout. Here‘s a Google search. The first page contains a lot of … Read more

[Solved] c++ platforms solving with dynamic programming

To restore path: Store additional n-sized array, say, prev[n], prev[0]=-1. If your dp decides for i’th step that you came from i-1, (i.e. dp[i – 1] + abs(v[i] – v[i – 1]) was larger than dp[i – 2] + 3 * abs(v[i] – v[i – 2])), then prev[i]=i – 1, otherwise prev[i]=i – 2. Then … Read more

[Solved] how do i implement heap data structure using c++? [closed]

Here is my simplest C++ implementation for heap. The code is well-commented. /* Usage: heap Heap; Heap.clear(); Heap.insert(value); Heap.remove(); Heap.print(); */ struct heap { int myarray[NN+1]; // myarray to store the numbers as heap, 1 indexed int n; // the number of nodes in my array heap() { // constructor clear(); // we clear the … Read more

[Solved] Get Substring – everything before and after certain characters [closed]

You could use regular expressions, e.g: class Program { static void Main(string[] args) { var input = ” SUCCESS Post Policy Success INVOICE No. :: WS1704003404 || Policy No :: 59203313 || App No. :: 123456724 “; var pattern = @”::\s*(\w+)\s*”; var matches = Regex.Matches(input, pattern); foreach (Match match in matches) Console.WriteLine(match.Groups[1].Value); } } 1 … Read more

[Solved] How to return “” OR empty when value of float is 1

You have marked this as C++ (4-1i) should be shown as (4-i) You might find std::stringstream helpful. It simplifies the special handling for the imaginary part: virtual int foo() { std::cout << std::endl; show(4, -2); show(5, -1); return(0); } void show(int real, int imaginary) { std::stringstream ss; // default is blank if (-1 == imaginary) … Read more