Well, I have been using John Smiley's Learn to Program with C# and MSDN in learning C#, and so far I understand the basic commands and such. I understand how to make custom methods... how to use control commands... and some basic input/output... but there is one thing I really just dont understand and that is how Instantiable classes work. I just cant wrap my head around it.... if someone could help me by giving me a few links or some definition that could help me understand how/what/who/why/etc it would be much appreciated.



Code:

using System;
public class Banner{
public string favoriteProgram;
public void Display() {
Console.WriteLine("I Love" + favoriteProgram);


this is the instantiable class while


Code:
 
public class Example {
public static void Main(string[] args) {
Banner x = new Banner ();
x.favoriteProgram = "C#"
x.Display()
}
}


is the start up class

I really just dont understand what is going on here Sad
http://en.wikipedia.org/wiki/Object-oriented_programming
Kllrnohj wrote:
http://en.wikipedia.org/wiki/Object-oriented_programming
Pretty much this. Smile Classes, instantiation of classes as objects, and use of those objects, including their members, is key to OOP. Make sure you understand those concepts first rather than diving right into the middle.
Errr, yyyeeaahhh, benr kinda cleared this up for me.... the trouble I was having was with banner x = new Banner()

basically, nothing to do with not understanding concepts, just not understanding how the banner x = new Banner() worked. Benr helped me though Very Happy
Would you mind giving us a brief description then, in your own words, both to cement your understanding in your mind and to give us an opportunity to correct any misapprehensions in your understanding?
what would you like me to explain then to cement my understanding?
qazz42 wrote:
what would you like me to explain then to cement my understanding?
Well, how about the difference between a class and an instantiated class (a class instance), what a member is, what a method is, what the differences between private, protected, public, and internal member/ method/ classes are, etc?
Oh, that is... 90% easy Very Happy

1. Instantiable classes are classes what are called on by the normal class and contain information and methods, sort of like a blueprint of a house, that the other classes can use

2. Idk what a member is

3. A method is... errr. I know what it is, No, really, I do, I just dont know how to explain it in words...

4. The differences between private/protected/public methods is the scope they have in the overall program. Idk about the internal thing though, that has to do with assemblies, which I do not know how to use and will not for a while...
1. Yeah, that's more or less correct. A class defines what methods and members an instance of that class has. Each instance of the class is like an individual person, while the class itself is an idea of what a person is.

2. A member (or field) is something like a variable that is part of a class

3. A method is like a member, except that it's a function that is part of a class

4. Scope is the wrong word to use, because scope refers to local/global. I get what you're saying, though. Internal doesn't specifically have to do with assemblies, but it's most relevant in that context.

I'd recommend re-reading the stuff you read on this. Smile
KermMartian wrote:
4. Scope is the wrong word to use, because scope refers to local/global. I get what you're saying, though. Internal doesn't specifically have to do with assemblies, but it's most relevant in that context.


No, scope is fine. The technically correct word in .NET land is "accessibility", though.
Kllrnohj wrote:
KermMartian wrote:
4. Scope is the wrong word to use, because scope refers to local/global. I get what you're saying, though. Internal doesn't specifically have to do with assemblies, but it's most relevant in that context.


No, scope is fine. The technically correct word in .NET land is "accessibility", though.
Are you sure? I thought scope referred specifically to thinks like:


Code:
int iAmGlobal = 1;

int myfunc(args) {
    printf("%d\n",iAmGlobal); //1
    int i=300;
    printf("%d\n",i); //300
    {
        int i=9001;
        printf("%d\n",i); //9001
    }
    printf("%d\n",i) //300
}
KermMartian wrote:
Are you sure? I thought scope referred specifically to thinks like:


It does, but it is still fairly common to see people call use scope when talking about public/private/protected/internal.
Kllrnohj wrote:
KermMartian wrote:
Are you sure? I thought scope referred specifically to thinks like:


It does, but it is still fairly common to see people call use scope when talking about public/private/protected/internal.
Fair enough, my mistake. For what it's worth, languages like Java and C++ use the term "friend" instead of "internal", Qazz.
KermMartian wrote:
Fair enough, my mistake. For what it's worth, languages like Java and C++ use the term "friend" instead of "internal", Qazz.


friend and internal do two totally different things. In C#, internal means anyone in the assembly can access the data. Friend, on the other hand, selectively grants specific classes access to a classes private fields.

They do have one thing in common, though, they are both pointless and stupid.
Haha Kerm, I am just having problems with trying to explain things of the top of my head. And I agree with killer, I should have said accessibility, but I rather use scope because it helps me remember it a bit more Razz

also, I dont know what you were saying with that code you posted with me never being proficient on C++ and Java...

once more, I have troubles explaining! I know what it is, but cannot explain without being wrong/sounding weird/sounding like I am talking to a 5-year-old x.x
My code (which is now pretty and colored, thanks to Prettify) demonstrates both local vs. global variables, and the hierarchy of nested scopes. If any of that sounds alien to you, you should look it up and clarify it for yourself.
alrighty then, new topic. I need some help with this code right here

http://pastebin.com/0hCLT439

basically it can load an image, but now the part I am having trouble with involves changing pixels of the picture (this is a simple image editor)

I beleive the line of code that gives me the most trouble is


Code:
Graphics gra = new Graphics();


I would like to know how to get graphics to work because I need to use the DrawLine method...
Other than leaking memory like a sieve* (you should Dispose GDI+ objects when you are done with them - see the using statement) your main issue is that you need to determine what you are drawing on. In your case it would be the Image in the PictureBox, so use Graphics.FromImage to create an instance of the Graphics object that draws to an Image (rather than, say, a Control).

Code:
private void pictureBox1_Click(object sender, EventArgs e)
{
   using (Graphics gra = Graphics.FromImage(pictureBox1.Image))
   {
      Point pnt1 = new Point(MousePosition.X);
      Point pnt2 = new Point(MousePosition.Y);
      using (Pen pen1 = new Pen(colordiag.Color))
      {
         gra.DrawLine(pen1, pnt1, pnt2);
      }
   }
   pictureBox1.Refresh();
}


The usual recommendations about descriptive variable names and error handling should also apply.

__________________
* More than a slight exaggeration. Smile
alrighty, so, now I have

http://pastebin.com/uQvSTpHe

looks good now, so I shall now focus on making a line that does something other then go from the top right corner to the top left corner.
Works for me; have you selected a colour?

Note that the Points you're drawing the line between are fairly nonsensical (what were you intending them to be?) If you change them to

Code:
Point pnt1 = new Point(10, 10);
Point pnt2 = new Point(30, 30);


you should definitely see something (providing the loaded picture is large enough).
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement