Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the implementation skills related to .NET Framework initialization?

Shulou Source: shulou.com Published: 2022-06-02 11:39:30 09月10日 Update

This article to share with you is about. NET Framework initialization related implementation skills is how, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after harvest, not much to say, follow Xiaobian to see it.

How to correctly apply. NET Framework determines the future programming efficiency of developers. Here we will first understand the operation methods related to initialization of the. NET Framework. If a class has public fields, you can initialize these fields when creating an object instance of the class using the following code:

. NET Framework Implicit Type Variables Related Concepts Detailed Explanation

. NET Framework Open Source Benefits Analysis

. NET Framework Lambda Expression Related Concepts

. NET Framework Timer Object Application Tips Sharing

. NET Framework Type Library Basic Feature List Summary

public class MyClass

{

public String field1;

public int field2;

public bool field3;

}

MyClass my = new MyClass();

my.field1 = "abcd";

my.field2 = 44;

my.field3 = true;

C #3.0 provides a simpler. NET Framework initialization method to initialize these public variables, as follows:

MyClass my = new MyClass { field1 = "abcd", field2 = 44; field3 =true; };

The. NET Framework initialization code above is written somewhat like a constructor with parameters, but instead of calling a constructor with MyClass (because MyClass doesn't have a constructor with three parameters), it's just a magic trick played by the C#compiler. In fact, the above code, after compilation, is still the same as using traditional initialization fields. It just seems simpler grammatically (at least not as many my's). Note that fields initialized using this method must be public (fields that cannot be protected, private, or default modifiers).

C#3.0 also improves how collection classes are initialized (making them initialized like arrays). Unfortunately, this initialization method only supports collection classes that use generics, that is, only collection classes that implement System.Collections.Generic.ICollection can use this initialization method. The code is as follows:

List

< string>

myList = new List

< string>

{ "data1", "data2", "data3" };

foreach (string data in myList)

{

textBox1.AppendText(data);

}

The above is what the implementation skills related to. NET Framework initialization are. Xiaobian believes that some of the knowledge points may be what we see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Methods codes fields techniques methods facets parameters variables just objects more concepts knowledge articles types applications compilation simplicity regret three Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi vpn Apple MariaDB