Click here to Skip to main content
       

C#

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
GeneralRe: Generics in C#membersrikumarrampa22 May '13 - 19:37 
Thanks a lot Alan, This approach has resolved my issue!
AnswerRe: Generics in C#memberBillWoodruff20hrs 22mins ago 
You can do this:
if (insd.GetType() is Class1<IByte>) {} // throws an error if 'insd is not defined
But, using a temporary variable and the "as" operator is more performant than using "is," and will not throw an error:
Class1<IInt> testObject = insd as Class1<IInt>;
if (testObject != null) Console.WriteLine("it's Class1<int>");
Is your goal here to test an "unknown" object's type at run-time, and then take action based on the underlying type? If so, there are other strategies you can use.
 
yours, Bill
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis

QuestionPassing Cursor Coordinates as Parameters [modified]memberASPnoob20 May '13 - 21:52 
Hi All,
I am trying to create a function that passes the cursor's starting and ending x,y coordinates as parameters. For instance I would like to set the cursor's starting x,y coordinate when the user clicks the left mouse button. Then as the user holds down the left mouse button and drags the cursor to a desired location, the ending x,y coordinate is dynamically set and updated. The final ending coordinate is set when the left button is released. I am currently working with the following code:
 
 private void Cursor_Coord(out Cursor C1, out Cursor C2)
{
   // Set the Current cursor, move the cursor's Position,      
   Cursor C1;
   Cursor C2;
   
   if(Mouse.LeftButton == MouseButtonState.Pressed)
   {
     C1 = new Cursor(Cursor.Current.Handle);
     C1.Position = new Point(Cursor.Position.X,  Cursor.Position.Y);
   }
 
   if(Mouse.LeftButton == MouseButtonState.Released)
   {
     C2 = new Cursor(Cursor.Current.Handle);
     C2.Position = new Point(Cursor.Position.X, Cursor.Position.Y);
   }
}
 
I am planning to send the changing cursor coordinates to the Drawline method to be used as the first and second point. The effect I have in mind is that the line is drawn as the mouse is in motion. The problem is it's not working. Any help will be greatly appreciated, thanks in advance.

modified 3 days ago.

AnswerRe: Passing Cursor Coordinates as ParametersprotectorPete O'Hanlon20 May '13 - 22:01 
You don't need to use a cursor to do this. As you've rightly noted in your code, the part you are actually interested in is the Position - that's all you need to keep track of.
I was brought up to respect my elders. I don't respect many people nowadays.

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Passing Cursor Coordinates as ParametersmemberASPnoob20 May '13 - 22:05 
Hi, you've replied to my post as I was in the process of making changes to it.
AnswerRe: Passing Cursor Coordinates as ParametersprotectorOriginalGriff20 May '13 - 22:52 
This is pretty easy to do, but I think you are trying to do it the wrong way. You don't say what your environment is, but I'll assume WinForms.
First off, you probably don't need to use Cursor at all for this, a simple Point is enough.
Try doing this by adding a few class level variables, and handling a few events:
private Point pointStart;
private Point pointEnd;
private bool drawing = false;
private void frmMain_MouseDown(object sender, MouseEventArgs e)
    {
    pointStart = e.Location;
    pointEnd = pointStart;
    drawing = true;
    Invalidate();
    }
 
private void frmMain_MouseUp(object sender, MouseEventArgs e)
    {
    drawing = false;
    }
 
private void frmMain_MouseMove(object sender, MouseEventArgs e)
    {
    if (drawing)
        {
        pointEnd = e.Location;
        Invalidate();
        }
    }
 
private void frmMain_Paint(object sender, PaintEventArgs e)
    {
    e.Graphics.DrawLine(Pens.Blue, pointStart, pointEnd);
    }
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

GeneralRe: Passing Cursor Coordinates as Parameters [modified]memberASPnoob21 May '13 - 16:38 
Hi, thanks for your reply. I have used your code but VS2010 is complaining that the Invalidate method does not exist in the current context. I assumed that Invalidate is a built-in function of C# but it doesn't appear to be the case.

modified 2 days ago.

GeneralRe: Passing Cursor Coordinates as Parametersmemberlukeer21 May '13 - 21:47 
Invalidate()[^] is a method of the System.Windows.Forms.Control[^] class. As such, it can be called on all its derivates.

Ciao,
 

luker

GeneralRe: Passing Cursor Coordinates as ParametersprotectorOriginalGriff21 May '13 - 22:21 
At a guess, you have added the word "static" in there somewhere - static methods cannot access non-static class methods, fields or properties.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

QuestionPropertyGrid Multiple Objects Selectionprofessionalvvino202020 May '13 - 20:48 
Hi, I need the coding for multiple object selection in propertygrid.
Please reply as soon as possible Wink | ;)
AnswerRe: PropertyGrid Multiple Objects SelectionmvpEddy Vluggen20 May '13 - 22:32 
vvino2020 wrote:
Hi, I need the coding for multiple object selection in propertygrid.
We "help" with coding-questions; if you need someone to write code for you, then this is the wrong place.
 
vvino2020 wrote:
Please reply as soon as possible Wink | ;)
I wouldn't "wait" with the answer just for the fun of it, and this question isn't more important than the other questions.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

AnswerRe: PropertyGrid Multiple Objects SelectionprofessionalSimon_Whale20 May '13 - 22:52 
Have a play with the MultiSelect property on the grid
Every day, thousands of innocent plants are killed by vegetarians.
 
Help end the violence EAT BACON

AnswerRe: PropertyGrid Multiple Objects Selectionmemberlukeer21 May '13 - 21:58 
Assign an array of objects to PropertyGrid's SelectedObjects[^] property. Note the plural-s.
PropertyGrid will then sort out what properties to display and what values to display for shown properties in the usual way.

Ciao,
 

luker

QuestionNot able to use Modern UI Charts for Windows 8professionalRaghavendra Reddy C20 May '13 - 18:40 
Hi,
 
I am trying to use Modern UI Charts for my Windows Store app but I am not able to get it working.
A similar issue was logged by another person here along with the code
 
Can anyone please help??
AnswerRe: Not able to use Modern UI Charts for Windows 8mvpAbhinav S20 May '13 - 18:49 
Does this third party support WIndows 8? Check if they have documentation that tells you what versions they support.

GeneralRe: Not able to use Modern UI Charts for Windows 8professionalRaghavendra Reddy C20 May '13 - 20:30 
Yes it does.. Clearly stated in the documentation
AnswerRe: Not able to use Modern UI Charts for Windows 8protectorPete O'Hanlon20 May '13 - 21:40 
Raghavendra Reddy C wrote:
Can anyone please help??

Given how little information you've given us, no. There's no source for us to view, and there's precious little detail about not being able to get it working in there.
I was brought up to respect my elders. I don't respect many people nowadays.

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Not able to use Modern UI Charts for Windows 8professionalRaghavendra Reddy C20 May '13 - 22:35 
Hi Pete,
 
I have added the link to the issue raised in the codeplex project site
https://modernuicharts.codeplex.com/workitem/16197[^]
 
A sample project is attached there
GeneralRe: Not able to use Modern UI Charts for Windows 8protectorPete O'Hanlon20 May '13 - 22:54 
Try this[^]
I was brought up to respect my elders. I don't respect many people nowadays.

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

AnswerRe: Not able to use Modern UI Charts for Windows 8professionalRaghavendra Reddy C20 May '13 - 22:53 
Got the solution. Thanks to Xyroid.
 
http://stackoverflow.com/questions/16662201/not-able-to-use-modern-ui-charts-for-windows-8[^]
AnswerRe: Not able to use Modern UI Charts for Windows 8mvpRichard MacCutchan20 May '13 - 22:54 
Raghavendra Reddy C wrote:
A similar issue was logged by another person here along with the code
And also a link to the solution.
Use the best guess

QuestionPROBLEM with SEND DATA to LOCAL PORT C#memberAndrew Nguyen20 May '13 - 17:18 
hi,
I am trying to write some data to local port to open the cash drawer....
with this simple code
 
private void button1_Click(object sender, EventArgs e)
{
    serialPort1.Open();
    //serialPort1.PortName(textBox1.Text);

    serialPort1.PortName = textBox1.Text;
    serialPort1.Write("16 20 1 0 1");
    serialPort1.Close();
}
 

However the Port is not recoginized in C# unless it's a COM port...
My printer somehow say it should be a local port with the name USB_BTP-R880NP_1 (as the name of the printer) .. How can i communicate with it without using a COM command from C#...
Second question is
in the reference, it said to send data to the port to open cash drawer by following this format :
ASCII DLE DC4 n m t
HEx 10 14 n m t
Decimal 16 20 n m t
Range n = 1
m =0,1
1<=t <= 6
Is my command above correct?
Thanks
 


AnswerRe: PROBLEM with SEND DATA to LOCAL PORT C#memberRon Beyer20 May '13 - 17:56 
Surprisingly, the SerialPort class in C# is designed specifically to talk to serial ports... You cannot talk to a USB device through the SerialPort class, no matter what name you give it. It will only work with COM ports.
 
Most cash drawers are serial though, are you sure that the cash drawer is connected via usb? If thats the case, you will need to get some sort of driver API to communicate with the usb device through a windows driver and hooks, not a very easy task. Sending raw data to a USB port through the WinAPI involves knowing device descriptors and endpoints that are difficult to know unless you have an intimate knowledge of the driver structure.
 
As far as your second question, thats something only the manufacturer can tell you. Without having more knowledge on our part, like a manual or interface document, we can't tell you if what you typed is right or wrong.
QuestionUsage of IDataErrorInfomemberradkrish20 May '13 - 8:11 
Hello All
I am trying to implement MVVM and use IDataErrorInfo interface to validate data in the model classes
 
I base model class implementing IDataErrorInfo interface
 
public class BaseClass: IDataErrorInfo
{
   <Properties and Members of BaseClass>
 
        #region IDataErrorInfo
        public string Error
        {
            get { return String.Empty; }
        }
        public string this[string PropertyName]
        {
            get { return this.GetValidationError(PropertyName); }
        }
        #endregion
}
 
Now I want drive a class from Base class
 
public class DrivedClass: BaseClass
{
}
 
How do I use IDataErrorInfo members in the derived class to carryout validation of the properties in the derived class??
AnswerRe: Usage of IDataErrorInfomemberRon Beyer20 May '13 - 14:55 
You can mark them as virtual and override them in the derived class.
GeneralUnderstanding Jagged Arrays [modified]memberWidmarkRob20 May '13 - 3:29 
Okay, declaring arrays is fairly simple… Just like declaring any other variable with the exception of the square brackets.
Initializing one-dimensional arrays also seems fairly simple enough… Initializing two-dimensional arrays is a bit more complicated but still semi-sort of simple if you pay attention to what you're doing.
Jagged arrays, like two-dimensional arrays… Can be a little tricky if you're not paying attention.
I get and understand the declaration and initialization of the jagged arrays, and that you can change the value of any element by re-declaring your array variable…
 
I'll use the example from the book I'm reading:
(never mind some of the missing closing curly brackets, before I add any more code I want to understand and learn this part first)
 
// Example 4-10.cs
// Jagged array example

using System;
class JaggedClass
{
    static void Main ()
{
    int[][] myJaggedArray = { new int[] {2, 3, 4}, new int[] {5, 6, 7, 8, 9} };
myJaggedArray[0][0] = 11; // This is changing the first element in both arrays to 11, right?
myJaggedArray[1][2] = 22; //this is changing the first element in the first array to 22 and changing the second element in the second array to 22, right?
 

Okay, you old pros… Here is the drill/exercise I was supposed to work on:
 
Drill 4-3
Display the contents of the two-dimensional array called “grades”
that was discussed in this section. Make sure you get the following
result:
 
Grade=Pass Score=55%
Grade=Good Score=65%
Grade=VeryGood Score=75%
Grade=Distinct Score=85%
 

The book was showing us three different ways to declare and initialize a two-dimensional arrays.
This is the first way it showed us:
string[,] grades = new string[2, 4] { {"Pass"," Good", "VeryGood", "Distinct"}, {"55%", "65%", "75%", "85%"} };
this is the second way:
string[,] grades = new string[,] { {"Pass", "Good", "VeryGood", "Distinct"}, {"55%", "65%", "75%", "85%"} };
third and final way:
string [,] grades = { {"Pass", "Good", "VeryGood", "Distinct"}, {"55%", "65%", "75%", "85%"} };
 
I know I probably could have achieved the same result with a "for loop, or a for each loop, maybe even the while loop", but… I couldn't quite figure it out,Confused | :confused: I beat my head against the wall for almost half an hour trying to figure the loop out…Mad | :mad: So, I went a different route… The long and hard way… Roll eyes | :rolleyes:
 
It took me about 15 min., maybe even 20 min. to even figure that out… My ah-ha moment came when I accidentally printed to the screen the word "Good"… Don't laugh… Cry | :(( I said don't laugh at! Poke tongue | ;-P
 
I wrote it and I achieved the way it looks in the book, you'll have to compile it in debug it yourself to see what it looks like… I haven't figured out how to format things here in the forum yet.
 
using System;
using System.Text;
 
namespace Two_Dimensional_Array
{
    class Program
    {
        static void Main(string[] args)
        {
            string[,] grades = { { "Pass", "Good", "VeryGood", "Distinct" }, { "55%", "65%", "75%", "85%" } };
            string[] gradeScore = {"Grade=", "Score="};
            Console.WriteLine(gradeScore[0] + grades[0, 0] + "         " + gradeScore[1] + grades[1, 0]);
            Console.WriteLine(gradeScore[0] + grades[0, 1] + "         " + gradeScore[1] + grades[1, 1]);
            Console.WriteLine(gradeScore[0] + grades[0, 2] + "     " + gradeScore[1] + grades[1, 2]);
            Console.WriteLine(gradeScore[0] + grades[0, 3] + "     " + gradeScore[1] + grades[1, 3]);
            Console.Read();
        }
    }
}


modified yesterday.

GeneralRe: Understanding Jagged ArraysprofessionalRichard Deeming20 May '13 - 3:44 
WidmarkRob wrote:
myJaggedArray[0][0] = 11; // This is changing the first element in both arrays to 11, right?
myJaggedArray[1][2] = 22; //this is changing the first element in the first array to 22 and changing the second element in the second array to 22, right?

Not quite. A jagged array is essentially an array of arrays. In your sample code, the myJaggedArray variable is an array containing two elements: an array of three integers, and an array of five integers.
 
myJaggedArray[0] returns the first element, so myJaggedArray[0][0] = 11 is updating the first element of the array stored in the first element of myJaggedArray, and myJaggedArray[1][2] = 22 is updating the third element of the array stored in the second element of myJaggedArray.
 
http://msdn.microsoft.com/en-us/library/2s05feca.aspx[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Understanding Jagged ArraysmemberWidmarkRob20 May '13 - 4:00 
myJaggedArray[0][0] //the first set of brackets closest to the variable is telling me to access the first element in the jagged array? Then the set of brackets furthest away from the variable is telling me to access the first element, inside of the first element of the jagged array?

GeneralRe: Understanding Jagged ArraysprofessionalRichard Deeming20 May '13 - 4:19 
WidmarkRob wrote:
the first set of brackets closest to the variable is telling me to access the first element in the jagged array? Then the set of brackets furthest away from the variable is telling me to access the first element, inside of the first element of the jagged array?

Yes, that's correct.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Understanding Jagged ArraysmvpRichard MacCutchan20 May '13 - 5:12 
In addition to Richard Deeming's comments, a 2 dimensional array is just like a square (or oblong) containing N rows, and M columns. So element[0][0] is row 0, column 0, and element[1][2] is row 1 column 2. Try the following for a better illustration:
int[][] myJaggedArray = { new int[] { 2, 3, 4 }, new int[] { 5, 6, 7, 8, 9 } };
for (int N = 0; N < myJaggedArray.GetLength(0); ++N)
{
    for (int M = 0; M < myJaggedArray[N].GetLength(0); ++M)
    {
        Console.WriteLine("element[{0}, {1}] = {2}", N, M, myJaggedArray[N][M]);
    }
}
Use the best guess

GeneralRe: Understanding Jagged ArraysmemberWidmarkRob20 May '13 - 6:04 
one thing I'm going to have to remember about two-dimensional arrays is that the first set of brackets closest to the variable are rows and the second set of brackets are the columns?
Then having to remember if it's a jagged array, the two sets of brackets are accessing the elements differently.
 
Newbie question… You can declare and initialize brand-new data types and variables in the conditional expression/statement?

GeneralRe: Understanding Jagged ArraysmvpRichard MacCutchan20 May '13 - 7:19 
WidmarkRob wrote:
and the second set of brackets are the columns?
Exactly, it gets a bit more complicated when you go to 3 or more dimensions.
 
WidmarkRob wrote:
You can declare and initialize brand-new data types and variables in the conditional expression/statement?
Sorry, but I don't understand what you mean by that.
Use the best guess

GeneralRe: Understanding Jagged ArraysmemberWidmarkRob20 May '13 - 7:30 
This I can see is the start of the for loop with the conditional expression/statement in the parentheses.
 
You don't have to declare and initialize a variable before starting the for loop?
It looks like you're declaring and initializing a variable as part of the conditional expression/statement and then using the variable right after that…
is my verbiage all wrong? Poke tongue | ;-P
for (int N = 0; N < myJaggedArray.GetLength(0); ++N)

GeneralRe: Understanding Jagged ArraysprofessionalMatt T Heffron20 May '13 - 8:49 
Yes, you can declare and initialize the loop control variable in the for statement itself.
http://msdn.microsoft.com/en-us/library/ch45axte.aspx[^]
Note that the scope of that variable is only the loop.
Specifically, you cannot examine that variable after the exiting the loop.
GeneralRe: Understanding Jagged ArraysmvpRichard MacCutchan20 May '13 - 22:26 
WidmarkRob wrote:
is my verbiage all wrong?
Not really, perhaps, my understanding was. Your question (I think) is about where to declare the loop variable. It is largely a question of where the variable is to be used. Consider the following code:
// first sample
int index;
for (index = 0; index < someValue; ++index)
{
    // do some stuff here
}
if (index == someOtherValue)
// ... at this point we can use the final value of the variable because it
//     was declared outside of the for statement.

 
// second sample
for (int index = 0; index < someValue; ++index)
{
    // do some stuff here
}
if (index == someOtherValue)  // ERROR
// ... at this point we cannot use the final value of the variable because it
//     was declared inside the for statement, and does not exist outside the loop.
// i.e the scope of the variable is within the for statement and its block, bounded
// by the curly braces.
Use the best guess

GeneralRe: Understanding Jagged ArraysmemberWidmarkRob7hrs 21mins ago 
Richard MacCutchan wrote:
myJaggedArray.GetLength(0);

either my book doesn't cover this method you're using or it did and I forgot and I have to go back and read it, I know your buddies book probably covers that, I will read it later…
 
One other thing, you start talking about two-dimensional arrays and then you post in your code a jagged array.
 
Jagged Array
int [][]
 
Two-dimensional Array
int [,]
 
Right?

GeneralRe: Understanding Jagged ArraysmvpRichard MacCutchan2hrs 3mins ago 
WidmarkRob wrote:
Right?
Excactly so; I was merely trying to illustrate how to look at the 'shape' of an array that has only two dimensions. Thinking about it in terms of rows and columns has always helped me when working with arrays.
Use the best guess

GeneralRe: Understanding Jagged ArraysmemberWidmarkRob1 hr 30mins ago 
I don't know if you had seen what my drill/exercise was supposed to be… I'm willing to bet a case of beer you be able to figure it out by looking at what I wrote…
I wrote it out the long and hard way… Only because at first, I couldn't quite figure out how to incorporate the for loop.
using System;
using System.Text;
 
namespace Two_Dimensional_Array
{
    class Program
    {
        static void Main(string[] args)
        {
            string[,] grades = { { "Pass", "Good", "VeryGood", "Distinct" }, { "55%", "65%", "75%", "85%" } };
            string[] gradeScore = {"Grade=", "Score="};
            Console.WriteLine(gradeScore[0] + grades[0, 0] + "         " + gradeScore[1] + grades[1, 0]);
            Console.WriteLine(gradeScore[0] + grades[0, 1] + "         " + gradeScore[1] + grades[1, 1]);
            Console.WriteLine(gradeScore[0] + grades[0, 2] + "     " + gradeScore[1] + grades[1, 2]);
            Console.WriteLine(gradeScore[0] + grades[0, 3] + "     " + gradeScore[1] + grades[1, 3]);
            Console.Read();
        }
    }
}
 
After fiddling around with it for a couple of days, I was able to get the for loop in… But, as you'll notice from the code above… The first two lines that print to the screen are spaced out just a little bit further so the Score column is all lined up just like the way they wanted in the book.
Is there some sort of extra C# technique/trick to have the columns line up?
using System;
 
namespace Two_Dimensional_Array
{
    class Program
    {
        static void Main(string[] args)
        {
            string[,] grades = { { "Pass", "Good", "VeryGood", "Distinct" }, { "55%", "65%", "75%", "85%" } };
            string[] gradeScore = {"Grade=", "Score="};
            for (int a = 0; a < 4; a++)
                {
                    Console.WriteLine(gradeScore[0] + grades[0, a] + "      " + gradeScore[1] + grades[1, a]);
                }
                Console.Read();
        }
    }
}

GeneralRe: Understanding Jagged ArraysmvpRichard MacCutchan23mins ago 
WidmarkRob wrote:
Is there some sort of extra C# technique/trick to have the columns line up?
Yes, it's all provided by the use of format strings[^], which allow you to specify the width of a field and the alignment of its content. There are also standard shorthand format notations for date, time, currency etc, or you can create your own. So you could code something like:
Console.WriteLine("{0}{1,-8} : {2}{3}", gradeScore[0], grades[0, a], gradeScore[1], grades[1, a]);
// field {1} is placed in a field 8 characters wide, left aligned.

// alternatively
Console.WriteLine("Grade={0,-8} : Score={1}", grades[0, a], grades[1, a]);
Use the best guess

GeneralRe: Understanding Jagged ArraysmemberJasmine250120 May '13 - 10:44 
This is one thing C++ programmers must learn really well or you start to run into trouble. C# has taken the dangerous stuff away, but it's now so simple that programmers don't understand what's going on, and when the details matter, it's often tricky because those details are hidden from you.
 
So, I don't know if this will be helpful or not, but looking at arrays at the low level always helped me...
 
int x[5];
That's a single-dimensional array - in C++ it's just 5 memory locations (0000-0004) containing int VALUES.
 
int x[5][5];
That's a two-dimensional array, but it's still LINEAR in memory - it's 25 integers in a row (0000-0024) (note: I'm using decimal memory addresses here for simplicity)
 
int x[5][];
This is where it gets tricky - that initializes 5 pointers, which point to integer arrays which aren't initialized yet. We have to initialize them, so if we did this...
 
x[0] = new int[5];
x[1] = new int[2];
....etc...
 
Now, in x[0] we have a pointer, pointing to a (probably distant) memory location of 5 integers, same as the array in the first example (and x[1] points to a 2-element array). Our x array contains pointers to those other arrays. THAT is a jagged array (x is, not the arrays x points to). See the difference now between the two-dimensional and jagged? A two-dimensional array is just a continuous block of memory with a clever way of indexing it, and that block holds the actual values. A jagged array holds no values, only pointers to other arrays.
 
And, C++ allows us to do this...
int x[5][5];
x[22] = 42;
 
....which sets the value "42" in the 23rd element of the array, which is the same as element [4][2] (the third "column" of the 5th "row")
 
Confused yet?
GeneralRe: Understanding Jagged ArraysmemberWidmarkRob20 May '13 - 10:47 
I'm not trying to learn C++

GeneralRe: Understanding Jagged ArraysmemberJasmine250120 May '13 - 10:52 
Never the less, you are using a computer, and what I just said there is how a computer works. Understanding what I said there will help you understand C#, which takes what I said and wraps a complicated memory manager around all that. But at the low levels, C# is creating pointers and memory blocks and sticking values in there, and when you say "int x[5];" that is exactly what is happening in C#.
 
Look at my first paragraph - C# is insulating you from the details which could help you understand arrays.
GeneralRe: Understanding Jagged ArraysmemberWidmarkRob20 May '13 - 10:57 
http://www.codeproject.com/Messages/4568615/Re-Understanding-Jagged-Arrays.aspx
 
I get it…

GeneralRe: Understanding Jagged ArraysmemberWidmarkRob20 May '13 - 11:06 
if it'll make you feel any better, here is what I'm supposed to bring to the screen:
 
Grade=Pass Score=55%
Grade=Good Score=65%
Grade=VeryGood Score=75%
Grade=Distinct Score=85%
 
Drill 4-3
Display the contents of the two-dimensional array called “grades”
that was discussed in this section. Make sure you get the following
result:
 

I'm not taking any formal classes, but… This is a Drill/Exercise from an e-book I'm reading on C#
 
I will post my code and ask you fine people for input/feedback about how I did it and maybe how I could have done better…

GeneralRe: Understanding Jagged Arrays [modified]memberJasmine250120 May '13 - 11:18 
Oh, cool Smile | :)
 
Please post the link to the e-book you are using, so we can see the context a little better.
 
My example wasn't about teaching C++, it was about understanding what the computer does when you put certain instructions in C# and the low-level differences between the types of arrays. C# hides those details from you, so you can be more productive, but it reduces understanding. Understanding those low-level concepts can prevent you from creating performance and memory problems in your programs.
 
Ever wonder why Windows takes twice as much memory to do half as much stuff as Linux? This is why.
 
EDIT: This is one of the best questions we've got in a long time. I get tired of the "plz snd codez" questions.

modified 3 days ago.

GeneralRe: Understanding Jagged ArraysmemberWidmarkRob20 May '13 - 12:00 
http://www.brainmeasures.com/courses/online/626/c-sharp-certification.aspx
 
You'll be seeing a lot of me with these types of questions, I'm not a script kiddie trying to find an easy way out…
 
along with a few others such as yourself that have been helping me, Sir Richard MacCutchan had helped me with the last subject:
http://www.codeproject.com/Messages/4566422/Re-Method-Not-Returning-a-Value.aspx

GeneralRe: Understanding Jagged ArraysmemberJasmine250120 May '13 - 12:47 
WidmarkRob wrote:
I'm not a script kiddie trying to find an easy way out…

 
Yeah I respect that. It's kinda why I thought you might be receptive to the low-level explanation of what's going on with this. Many people just want to get their assignment done and don't care how well it comes out, and those people create a lot of problems in the industry. I do my best to try to not create any more folks like that, who can produce miles and miles of bad code, that works. My production environment is acting very funny today because of code like that.
GeneralRe: Understanding Jagged ArraysmemberWidmarkRob20 May '13 - 13:04 
the book I'm reading is very similar to this book:
http://www.charlespetzold.com/dotnet/
 
they are both nicely detailed and start out very similar, talking about the .net framework and a little history behind C#… How it took some of the concepts C and C++…
 
I'm going to read that other book, when I'm done reading the book that I paid for… Roll eyes | :rolleyes:

GeneralRe: Understanding Jagged ArraysmemberJasmine250120 May '13 - 13:31 
Everything he writes is good. I lived that history and it is fascinating. C# (and Java and other "managed" languages) solves a lot of the problems that C++ had where simple coding mistakes could lead to memory leaks and security problems. In C#, a lot of those coding mistakes just won't compile... like this...
 
if (x = y) {
   //do something
}
 
In C++ that was an "assignment and test" all in one line. It assigns the value of y to x and casts the whole expression to boolean, so if y was non-zero, the branch would execute. We almost never did that on purpose, we usually just forgot to say ==(the equality operator) instead of =(the assignment operator). You can still make this mistake in Javascript.
 
In C# we have to write it this way...
 
x = y;
if (x != 0) {
  //do something
}
 
It forces us to do the assignment and the test separately. This avoids the problem that often we would mistakenly write the first example, when what we meant was a simple test for equality. There's nothing illegal about doing assignment and testing in the same statement, but the C# compiler warns us that it's probably a mistake - you can force it to compile if you really want.
 
What I'm saying is C# (and Java) is mostly a reaction to C++ and all of the horrible things it would let you do! So, that's why it's helpful to see an example from old languages periodically and an explanation of why we don't do it that way any more, or why we do. In C#, arrays are managed objects, which is a step up from blocks of memory, but that managed object is just insulating you from all the mistakes that were easy to make when you were closer to the block of memory, which is still there, buried beneath objects. I would expect Petzold to cover that - how C++ was dangerous with memory, how we learned all the pitfalls, and built in safeguards right in the language.
GeneralRe: Understanding Jagged ArraysmemberWidmarkRob20 May '13 - 13:41 
the book I'm reading now sprinkles in comparisons to C++ every now and then… I got in maybe 20 pages into that other book before I realized they both started off pretty similar… That's when I stopped reading it.
There were a few things mentioned in Petzold's e-book that wasn't covered in the book I'm reading now, which is why am going to eventually read that book when I'm done with my current book.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 24 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid