Click here to Skip to main content
15,310,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am giving underneath a part of my code. While debugging I get two errors:

1. A local variable named 'c1' cannot be declared in this scope because it would give a different meaning to 'ç1'which is already used in a 'parent or current' scope to denote something else.

2. Cannot implicitly convert type 'int'to 'int[][]'.


My code is here:

C#
for (i = 1; i <= m; i++)
  {
    for (j = 1; j <= n; j++)
      {
         Console.WriteLine("Enter the values for c1[i][j]");
         int[][] c1 = Convert.ToInt32(Console.ReadLine()); //****error in this line
      }
   }


How should I rectify this error?
Posted
Updated 12-Jan-16 20:08pm
v2
Comments
   
What could possibly be unclear in this error message?
—SA
Member 12247039 13-Jan-16 1:45am
   
In the initial declaration step I have declared 'int[][] c1'.
I am referring to the same c1 again here. In this case I want to accept input from the user and store it in the c1 array.

In C language I had used the following statements:

for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("Enter the values for c1[%d][%d]",i,j);
scanf("%d",&c1[i][j]);
}
}

I wanted to have the same meaning while writing in C#.
   
You did not answer my question, but I answered yours in Solution 1. Did you read it?
—SA
Member 12247039 13-Jan-16 1:50am
   
I did read it. I gave you the explanation for that only. I know it has been used somewhere else and I told you where else it has been used. And this same array is referred to at many places in the logic. And there is only one array by the name c1[][].
   
I answered, but now I also see that this is not the same c1. Let's say, "the compiler is not sure". If you want too different objects, you can use my answer, if you think it's the same, you cannot do it. If you are still unsure what to do, you have to show all declarations and initializations of c1, whatever it means. I'll be able to figure out what to do. Don't forget the explain what you wanted to achieve.

Wait a second! Don't you think you misplaced your last comment above? It looks totally unrelated, not even C#, but C or C++...

—SA

What is unclear in this error message? Just rename this c1. You have another variable with this name elsewhere.

And do yourself a big favor, don't use such names, always uses something semantically sensible. Refer to (good) Microsoft naming conventions.

—SA
   
Comments
Member 12247039 13-Jan-16 1:47am
   
Yes sure. I have got to know pretty much through this forum. I am always on a continuous learning process. Thanks to you and all the experts here...!!!
   
You are welcome. Sure, it takes some learning; I really appreciate you are trying to learn.
Will you accept the answer formally then?
—SA
Member 12247039 13-Jan-16 1:53am
   
Thanks.
What does the second error message mean?
You can write your code like this
C#
for (int i = 1; i <= m; i++)
           {
               for (int j = 1; j <= n; j++)
               {
                   Console.WriteLine("Enter the values for c1[i][j]");
                    c1[i][j] = Convert.ToInt32(Console.ReadLine()); //**** this will not show any error 
               }
           }


hope it will work
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900