Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call C # instantiation and static class objects

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of C# instantiation and how to call static class objects, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to instantiate C# and static class objects. Let's take a look.

1. Contrast effect

No matter how many times the instantiated object is called, it will re-initialize the value call, indicating that the life cycle of the instantiated object ends after the call is completed.

Static class object, the static members under the static class will always occupy memory and only instantiate once, indicating that the life cycle of static class members is from the call to the end of the program or mechanism recycling.

The scene uses:

1) static class or member: database connection string, which can be defined as static, which is called and obtained frequently.

2) instantiation: login operation. General login operation is not too frequent.

Restart the corresponding IIS site

When constantly refreshing a page, the memory increases regularly according to the 0.1MB. After refreshing to a certain number of times, the memory does not increase significantly, or even remains the same. There are two .NET Core Host processes in the following figure, which refer to two sites and are called externally or internally, otherwise the status will not be displayed.

2. Instantiation code public string init = "instantiation: hello"; public bool flag = false;public int num = 0 flag public void Test (string one) {string test = ""; if (! flag) {flag = true; num + = 1; test = "[first output]" + init + one + num;} else {num + = 1; test = init + one + num } LmyLogHelper.Debug (test);} 3. Static class code public static string init = "static: hello"; public static bool flag = false;public static int num = 0polipublic static void Test (string one) {string test = ""; if (! flag) {flag = true; num + = 1; test = "[first output]" + init + one + num;} else {num + = 1 Test = init + one + num;} LmyLogHelper.Debug (test);} this article on "how to instantiate C# and how to call static class objects" ends here, thank you for reading! I believe you all have a certain understanding of the knowledge of "how to instantiate C# and how to call static class objects". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report