Implicit array casting in C# -


I have the following classes with a built-in Cast operator:

  class A {. ..} class B {private AM_A; Public B (AA) {this.m_a = a; } Public stable underlying operator B (AA) {return New B (A);     

But now I can do A to B.

  Fixed zero main (string [] args) {// compiles a a = new A (); BB = A; // A [] arrA = New A [] (New A), New A ()} does not compile; B [] arrB = arrA;}  

Thanks, Malki As Mehrdad Afshari has mentioned, you are out of luck actually doing it on this.

You have to be clear, and it will contain an array copy. Thankfully, you can do this with one-liner:

  arrB = arrA.Cast  B & gt; (). ToArray ();  

Although you only repeat the arrB in a foreach statement If you want to duplicate, you can avoid copying except toArray ()


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -