In variable List data will contain.
var UserList= ?????
In variable List data will contain.
var UserList= ?????
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tuhin PaulPosted Mar 20, 2023, 12:58 AM
Global variables can be used across multiple functions and methods, making them a convenient way to share data between different parts of a program. Global variables can be accessed from anywhere within the program, which makes them useful for storing frequently used data that needs to be accessed quickly and easily. Global variables can simplify the coding process by eliminating the need for passing data between functions and methods.
Tuhin PaulPosted Mar 20, 2023, 12:57 AM
Global variables are used in C# to store data that needs to be accessed from different parts of the program. They are typically declared outside of any functions or methods, which makes them accessible from anywhere within the program.
Global variables can make the code more complex and harder to understand, especially when dealing with large programs. Global variables can make the program less secure, as they can be modified from anywhere within the program, making it easier for attackers to exploit vulnerabilities. Global variables can create a dependency between different parts of the program, making it harder to modify and maintain the program over time.
Tuhin PaulPosted Mar 20, 2023, 12:56 AM
In this example, we have declared a static list of User objects named UserList. The static keyword indicates that this variable will be shared across all instances of the class.
You can initialize the UserList with data
Tuhin PaulPosted Mar 20, 2023, 12:54 AM
To declare a global variable in C#, you can use the
statickeyword along with the variable declaration.Manikandan MurugesanPosted Mar 18, 2023, 5:22 AM
In .NET Core, you can declare a global variable by defining it outside of any method or class, at the namespace level. Here's an example of declaring a global variable called
UserListin .NET Core:In this example, we define a static class called
Globalsthat contains the global variableUserList, which is aListobject. By making the classstatic, we can access the variable without creating an instance of theGlobalsclass.Note that using global variables can lead to various issues, such as making your code harder to test and maintain, and causing unexpected behavior due to shared state. It's generally a better practice to pass variables explicitly between methods or classes as needed, rather than relying on global state.