In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "the array introduction of non-zero middle and lower bound of C#". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First of all, take a look at the introduction to the array:
1. Array: a mechanism that allows multiple data items to be treated as a collection.
two。 Array classification: in CLR, arrays can be divided into one-dimensional arrays, multi-dimensional arrays, and interlaced arrays.
3. Array type: since all arrays inherit from the abstract type System.Array, and this type inherits from System.Object, this means that the array is a reference type.
When creating an array, in addition to having array elements, the memory block occupied by the array object also contains a type object pointer, a synchronization index block, and an additional member. The above classification of arrays refers to "interlaced arrays". Because CLR supports staggered arrays, it is possible to implement staggered arrays in C #, which is an array made up of arrays. Accessing the elements of a staggered array means that two or more array visits must be made.
In the process of performing related operations on an array, when the array is passed to a method as an argument, what is actually passed is a reference to the array, so the called method can modify the elements in the array. If you do not want to be modified, you must make a copy of the array and pass it to the method. )
Here is a way to convert an array to DataTable:
/ Integer 2D array is converted to DataTable / public DataTable DyadicArrayToDataTable (int [,] intDyadicArray, out string messageOut, params object [] dataTableColumnsName) {var returnDataTable = new DataTable () / / verify whether the column matches the characters passed in if (dataTableColumnsName.Length! = intDyadicArray.GetLength (1)) {messageOut = "the number of DataTable columns does not match the number of 2D array columns, please adjust the number of columns"; return returnDataTable;} / / add column for (var dataTableColumnsCount = 0) DataTableColumnsCount < dataTableColumnsName.Length; dataTableColumnsCount++) {returnDataTable.Columns.Add (dataTableColumnsname [dataTableColumnsCount]. ToString ());} / / add line for (var dyadicArrayRow = 0; dyadicArrayRow < intDyadicArray.GetLength (0); dyadicArrayRow++) {var addDataRow = returnDataTable.NewRow () For (var dyadicArrayColumns = 0; dyadicArrayColumns < intDyadicArray.GetLength (1); dyadicArrayColumns++) {addDataRows [dataTableColumns] .ToString ()] = intDyadicArray [dyadicArrayRow, dyadicArrayColumns];} returnDataTable.Rows.Add (addDataRow) } / / return prompt and DataTable messageOut = "DataTable successfully converted"; return returnDataTable;}
The above is the operation method of converting the integer array to DataTable. As for the conversion of other types, such as bytes and floating point types, you can modify the relevant parameters or modify the parameter types accordingly.
Next, let's take a look at the relevant knowledge of "lower bound non-zero array":
The lower bound non-zero array is less in general use because it is not better optimized in performance. if you ignore the performance loss or the need for cross-language migration, you can consider using a non-zero array. The concept of "lower bound non-zero array" is not introduced, as its name suggests.
C # is created using Array's CreateInstance () method, which has several overloads that allow you to specify array element types, array dimensions, the lower bound of each dimension, and the number of elements per dimension.
When CreateInstance () is called, memory is allocated to the array, parameter information is saved to the memory overhead portion of the array, and a reference to the array is returned.
Next, take a look at the underlying implementation code for this method:
[System.Security.SecuritySafeCritical] / / auto-generated public unsafe static Array CreateInstance (Type elementType, int length) {if ((object) elementType = = null) throw new ArgumentNullException ("elementType"); if (length < 0) throw new ArgumentOutOfRangeException ("length", Environment.GetResourceString ("ArgumentOutOfRange_NeedNonNegNum")); Contract.Ensures (Contract.Result ()! = null) Contract.Ensures (Contract.Result (). Length = = length); Contract.Ensures (Contract.Result (). Rank = = 1); Contract.EndContractBlock (); RuntimeType t = elementType.UnderlyingSystemType as RuntimeType; if (t = = null) throw new ArgumentException (Environment.GetResourceString ("Arg_MustBeType"), "elementType") Return InternalCreate ((void*) t.TypeHandle.Valuejor 1 recorder has null);}
If you see the above code, you should have a general understanding of the creation of a non-zero cardinality array, and then take a look at the underlying code of the Ensures () method:
Public static void Ensures (bool condition) {AssertMustUseRewriter (ContractFailureKind.Postcondition, "Ensures");} [SecuritySafeCritical] static partial void AssertMustUseRewriter (ContractFailureKind kind, String contractKind) {if (_ assertingMustUseRewriter) System.Diagnostics.Assert.Fail ("Asserting that we must use the rewriter went reentrant.", "Didn't rewrite this mscorlib?"); _ assertingMustUseRewriter = true Assembly thisAssembly = typeof (Contract) .Assembly; StackTrace stack = new StackTrace (); Assembly probablyNotRewritten = null; for (int I = 0; I < stack.FrameCount; iAssembly +) {Assembly caller = stack.GetFrame (I) .GetMethod () .DeclaringType.Assembly If (caller! = thisAssembly) {probablyNotRewritten = caller; break;} if (probablyNotRewritten = = null) probablyNotRewritten = thisAssembly; String simpleName = probablyNotRewritten.GetName () .Name System.Runtime.CompilerServices.ContractHelper.TriggerFailure (kind, Environment.GetResourceString ("MustUseCCRewrite", contractKind, simpleName), null, null, null); _ assertingMustUseRewriter = false;} "Array introduction of non-zero middle and lower bounds in C#". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.