-
Runs correctly after modification.
The problem is that the main function is also a member function of the class, and the local variables defined in the member function cannot be used by other member functions.
Criticism and correction are welcome if there is something wrong.
using system;
namespace hhxxdry
public class e
Changed: private static double count, e;
public static void main(string args)
int k;
double t = new double[100];
t[0] = ;
e = ;count = 0;
for (k = 0; k <= 20; k++)t[k + 1] = t[k] / k + 1;
The value of t is:", k + 1, t[k + 1]);
count++;
e = e + 1 / t[k + 1];
e aa = new e();
public e()
The value of e is", e);
1/k!The value of is", count);
-
Since the constructor of the class is executed first.
public e()
The value of e is",e);
1/k!The value of is",count);
In this case, the e and count are of course undefined variables.
Can be modified to:
public class e
private double count;
private double e;
Replace double count,e; Define the member variables of the class.
-
public e()
The value of e is",e);
1/k!The value of is",count);
Here's the construct, if you're going to use e in it
Then the e must be defined in the class, not in the main method.
-
e and count are local variables defined in the main function, which of course are not accessible in .
-
Agree with the ground floor.
lz, how can the variables you define in the main function be accessed in other functions?
-
Both issues are the same as the absence of declarations.
-
First of all, I will explain to you what is using
The usage rules for using as an introduction to namespace directives are:
using namespace;
At. In .NET programs, the most common ** is to introduce the system namespace at the beginning of the program file, the reason for which is that the system namespace encapsulates many of the most basic and common operations, and the following ** is the most familiar to us:
using system;
This allows us to use the type in the namespace directly in the program without having to specify a detailed type name. using directives to access nested namespaces.
About: Namespaces.
The namespace is. The logical organization of a .NET program, rather than the actual physical structure, is a way to avoid class name conflicts, and is used to divide different data types in combination. For example, in.
Many of the basic types in .net are located in the system namespace, and the data operation types are located in the namespace, okLet's go on. The question you asked is:
using requires a reference to the dll
You do an experiment. Create a new project in your solution. A class library project.
When you don't quote him. The using statement is also unusable. Right?
References must be added before you can use any namespace in your library.
According to the above two scenarios. It's obvious to know. c Medium. All DLL files are decoupled from your project.
Your project is also a separate namespace. There is no necessary connection between DLLs and DLLs.
Even if you look at it at the level of simply knocking on the **.
Just enter this to do. But when you create a new WinForm program.; It can't be used. The reason for this is: vs automatically referenced some dlls for you
Because there is a decoupling between DLLs and DLLs. There is no connection. So when you want to use a certain namespace. You have to reference the dll of that namespaceOtherwise, it is not possible to find the specific correspondence. Unable to quote correctly.
-
C references are not like C++ and other languages that can be used to include directly, C references you must add a reference to the dll before you can call the dll in the class
Trademark and application channels: You can go to the registration hall of the Trademark Office (Beijing) in person, or you can entrust a trademark ** agency to handle it. Documents required for application: >>>More
I don't know exactly what the other two friends mean, but it seems that they are all based on the flow of discussions. >>>More
#include
using namespace std; >>>More
The output of this program is: 4
You can standardize the program to make it easier to understand. >>>More
Scope. You static char *chh;
static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More