Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum Mimicking Array Names Being Defined at Runtime
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav // http://rextester.com/users/376 namespace Rextester { using SJA=Rextester.StringJaggedArray; class StringJaggedArray{ public string[][] X{get;set;} public int Length{get{return X==null?-1:X.Length;}} public static string[] operator +(StringJaggedArray x,int i){ return x.X==null as string[][]?null as string[]:x.X[i%x.Length]; } } class Program { public static void Main(string[] args) { string[] arr0={"A","B","C","D","E","F"},arr1={"1","2",},arr2={"@#","$%",},arr3={"abc","def",},arr4={"this","is","THE","END",}; SJA arr= new SJA{X= new[]{arr0,arr1,arr2,arr3,arr4}}; // Now, we can *mimic* names being defined at runtime, // writing just: arr+i // where i belongs to [0..i-max) // // The name of the array ( the main part) // must match the name of the variable of type SJA // and must be numbered sequentially starting at 0 for(int i=0;i<arr.Length;++i){ Console.WriteLine(arr+i); // here, mimicking an array name Array.ForEach(arr+i,x=>Console.Write("\t{0}",x)); Console.WriteLine("\n"); } } } }
run
|
edit
|
history
|
help
0
Generics
factorial ncr
pointer
ICollection<T>.Add(T) - Performance Test
sdfghjikujyhtgrfedwcdf
7
monopoly11
QuickSort
Get UTC time and offset minutes
CryptoJS vs AES