|
I want to initialize the values of a multi dimension array. Instead of this:
string[,] arr = {{"charles","mary","moses"},{"erik","ann","grace"}};
I'd want to do this:
string[] class1 = new string[3];
string[] class2 = new string[3];
class1[0] = "charles";
class1[1] = "mary";
class1[2] = "moses";
class2[0] = "erik";
class2[1] = "ann";
class2[2] = "grace";
string[,] arr = {class1,class2};
This is not working. It gives the error:
Invalid rank specifier: expected ',' or ']'
In the last line. The reason is that i have the values for the multi dimension array in single dimension arrays. What can i do to load Multi-Dimension Values like the above from single dimension arrays?Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
modified on Saturday, February 6, 2010 9:45 AM
|
|
|
|
|
A multidimensional array is not an array of array's, it's a single array with funky indexing.
If you change the declaration of arr to string[][] you could do what you want, but then of course it has become a jagged array (which just happens to accidentally be rectangular) instead of a multidimensional array.
If you really want a multidimensional array you could manually copy the arrays to their proper rows
|
|
|
|
|
Hello,
I wanna know If i declare function with same name, in interface and base class. and inherit this with Drived class. and call this function with drived obj.What Does it throws an error or not?
If not how its differentiates which function to call?
and how to call both the function?
EG:
<br />
Public Interface Iface<br />
{<br />
Void Display();<br />
}<br />
<br />
Public Class Base<br />
{<br />
Public Void Display()<br />
{<br />
Console.Readline("This is Base Class Method");<br />
} <br />
}<br />
<br />
Public Class Derived : Base, Iface<br />
{<br />
Public Void Display()<br />
{<br />
Console.Readline("This is Interface Method");<br />
} <br />
}<br />
<br />
Main()<br />
{<br />
Derived Dobj = new Derived(); <br />
Dobj.Display();<br />
Console.Readline();<br />
}<br />
Which function is called?
|
|
|
|
|
The interface will be called, Derived.Display() . After you fix the copiler-errors, since C# is case-sensitive I are Troll
|
|
|
|
|
And replace Console.Readline with Console.WriteLine!
Tch! The quality of code fragments is just getting worse and worse... If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
Yeah, it's good to see a post with an actual piece of code in it I are Troll
|
|
|
|
|
Ignoring the various errors in your code, the derived class Display will be called. To access the base clase method, use "base.Display()".
Derived Dobj = new Derived();
Dobj.Display();
public interface Iface
{
void Display();
}
public class Base
{
public void Display()
{
Console.WriteLine("This is Base Class Method");
}
}
public class Derived : Base, Iface
{
public void Display()
{
base.Display();
Console.WriteLine("This is Interface Method");
}
}
I think you need to read up on Interfaces: there is no code associated with an "interface method". The method you define in the Derived class implements the Interface method requirements, but masks the Base class implemenation - you will in fact can an error message to that effect that can only be got rid off by declaring it as "public new void Display()"If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
By definition, a static constructor is fired only once when the class is loaded. An instance constructor on the other hand is fired each time the class is instantiated. Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
That is a stupid question: if you have the code, then fix the minor bugs and run it!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Here's a thought - use the tools that come with the compiler, namely, the debugger..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
|
With what? Should I call the Police?I are Troll
|
|
|
|
|
No, no - he thinks you have a problem he can help with "Help you please". Do you require any assistance, at this time? Are you, perhaps, on fire? Lost at sea? If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
|
Oh good, my current requirements are:
A hierarchical user management system, permissions to be reflected in the navigation UI
A c# implementation of cubic spline
A better method of displaying a class via a propertygrid b/c the current one is crappy (or I can't make it behave yet)
Practical solutions to any of the above will be appreciated, preferably before Wednesday, as I expect to have them completed by them myself!Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Please let me know your expertise.... Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
but I are stupid....45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
What help you are looking for? Cheers!!
Brij
|
|
|
|
|
hi
i function c# can 3/4 float convert 4/3
|
|
|
|
|
I assume English is not your native language?
I am not sure what your question is asking.
Do you mean "Can I write a function to invert a fraction?" If so, then yes, just divide one by the existing value.
If not, then please explain in more detail.If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
Do you asking from data type conversion? Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Console.WriteLine("The inverse of 3/4 equals infinity");
Console.WriteLine("Do you know why?");
string reason=Console.ReadLine();
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
can c# not functions double 3/4 4/3 converts
|
|
|
|
|
loyal ginger wrote: can c# not functions double 3/4 4/3 converts
Does that mean you understand the OPs question?
In which case, could you explain it to me, in English?
Oh, and your answer, please!If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
I am just talking in the same language as the original poster. I can communite with him quite well this way. I understand the frustration you guys have with my post. However, my post is just another way to express the same frustration we all have.
We really need more sense of humor in this place. In my place we don't have much of anything interesting. By the way, my mother tongue is not English -- it's some language many people don't understand. I am glad we have a common platform to communite.modified on Saturday, February 6, 2010 9:13 PM
|
|
|
|