[Solved] Why i can not use reference variable?

You are trying to write execution code inside of a class. Please close it in a method, or any other execution code block and it will be ok. Following this article: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/class A class can contain declarations of the following members: Constructors Constants Fields Finalizers Methods Properties Indexers Operators Events Delegates Classes Interfaces Structs I … Read more

[Solved] string.Substring not working correctly in C#

It’s actually working correctly. There is a leading space on the string and thus the ninth index is the space just before the DU. Consider this diagram: Jun30/13 DU SJ9802 0123456789 You’re starting on the ninth index, and that’s a space . 1 solved string.Substring not working correctly in C#

[Solved] C# if then else issues [closed]

Your braces and try{} catch{} blocks are mismatched. Here is the corrected code: public partial class frmPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { try { DateTime dt1; DateTime dt2; if (txtFirstName.Text == “”) { txtFirstName.BackColor = System.Drawing.Color.Yellow; lblError.Text = “Please enter first name”; … Read more

[Solved] How can I use a class from a header file in a source file using extern but not #include?

Just to clarify. It is impossible to extern the class: class Outside { public: Outside(int count); GetCount(); } But, once you have the class available in framework.cpp, you CAN extern an object of type Outside. You’ll need a .cpp file declaring that variable: #include “outside.h” Outside outside(5); And then you can refer to that object … Read more

[Solved] What is the difference between assigning a pointer to variable address and explicitly to memory address?

Those are both undefined behavior. You are trying to modify memory that you did not allocate. The second is even less safe, because you are assuming a is going to be allocated to that address every time, which is absolutely not a safe assumption. 3 solved What is the difference between assigning a pointer to … Read more

[Solved] Unordered Random Numbers [closed]

if you want to generate random numbers in range without repeating, you can try this: public static List<int> GenerateNumbers(int mn,int mx) { List<int> source = new List<int>(); for (int i = mn; i <= mx; i++) source.Add(i); var random = new Random(); List<int> randomNumbers = new List<int>(); while(source.Count != 0) { int randomIndex = random.Next(source.Count); … Read more

[Solved] C++ struct in a vector in an object(class)

The problem is that you define a type (account) in the class. account is a type so you should not declare it in the class : struct account { std::string name; float money; short pin; }; and then, the class becomes : class CBank { public: CBank(); account acc; std::vector<account> add; }; and the main … Read more

[Solved] Write xml with c#?

So if I get it correct, you want to append new data to your existing xml. For that you can chose to temporarily store the current xml and and add new data to it using Linq Xml. To do this, now you need to modify your current code with an additional check for xml file … Read more

[Solved] Blatant floating point error in C++ program

80-bit long double (not sure about its size in MSVS) can store around 18 significant decimal digits without loss of precision. 1300010000000000000144.5700788999 has 32 significant decimal digits and cannot be stored exactly as long double. Read Number of Digits Required For Round-Trip Conversions for more details. 8 solved Blatant floating point error in C++ program