Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 629
  • Last Modified:

Error while initializing two-dimensional array

In the following code I attempted to initialize a two-dimensional string array. I want to initialize it with blank spaces. It is giving error: "Wrong number of indices in []". Please also correct the return type.
public static string[] StripOffSalt(string encryptedString)
    {
        string[,] SplittedArray =  new string[,];
 
        SplittedArray[0] = encryptedString.Substring(0, 11).ToString(); //Salt
        SplittedArray[1] = encryptedString.Substring(12);   //Original Encrypted String
 
    }

Open in new window

0
rpkhare
Asked:
rpkhare
  • 2
1 Solution
 
CuteBugCommented:
It should be
public static string[] StripOffSalt(string encryptedString)
{
    string[] SplittedArray = new string[2];
 
    SplittedArray[0] = encryptedString.Substring(0, 11).ToString(); //Salt
    SplittedArray[1] = encryptedString.Substring(12);   //Original Encrypted String
 
    return SplittedArray;
}

Open in new window

0
 
CuteBugCommented:
The above code will resolve the error.
But, since you wanted a two dimensional array it should be
public static string[,] StripOffSalt(string encryptedString)
{
    // you should specify the size of the array you want to create.
    // here i have created an array having two rows and 1 columns
    string[,] SplittedArray = new string[2,1];
 
    SplittedArray[0,0] = encryptedString.Substring(0, 11).ToString(); //Salt
    SplittedArray[1,0] = encryptedString.Substring(12);   //Original Encrypted String
 
    return SplittedArray;
}

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now