🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C# Workshop - Week 1 (Ch. 1 & 2) - Advanced

Started by
337 comments, last by paulecoyote 17 years ago
I have a little experience with C#, but not much, and I am finding it confusing as hell. I even looked past the first two chapters at the 3rd one, because I figured it would be easier to understand since it doesn't throw everything at you at once...it wasn't easier :(

I just want to see the project; I learn better when I have something to work at while I'm learning. It's like math, I can never understand it just by listening to the professor lecture, but rather by working the examples.
Advertisement
Quote: Original post by finky45
Any people here who are learning this as their first programming language?

I'm wondering how difficult is this for you? I've learned most of C++ before this and I find it somewhat challenging to keep up with all the keywords. I imagine for a new person all the new vocabulary must be overwhelming...

I know for me, these 2 chapters would scare the **** out of me =X

EDIT: Sorry, I'm not trying to discourage anyone, these 2 chapters must be the hardest - they're throwing everything at you at once. So if you get through these the rest should be much easier.


The contents is certainly quite extensive so far. The things i've read from chapter 1 so far, have already covered most of the OOP aspects that is usually covered in a C++ book. If this was my first language, I would be frightened for sure :)

However, i'm quite sure by looking at the table of contents, that this is some sort of "review" for what's coming.
Ok. Question. I'm sure someone in this thread touched on this earlier.

public class foo{   public void bleh ();};public class bar: foo{   public void bleh ();};


Is that wrong? Yes, the virtual is left out on purpose because I don't how the compiler or program could choke on this at runtime.

Beginner in Game Development?  Read here. And read here.

 

Quote: Original post by password
Quote: Original post by finky45
Any people here who are learning this as their first programming language?

I'm wondering how difficult is this for you? I've learned most of C++ before this and I find it somewhat challenging to keep up with all the keywords. I imagine for a new person all the new vocabulary must be overwhelming...

I know for me, these 2 chapters would scare the **** out of me =X

EDIT: Sorry, I'm not trying to discourage anyone, these 2 chapters must be the hardest - they're throwing everything at you at once. So if you get through these the rest should be much easier.


The contents is certainly quite extensive so far. The things i've read from chapter 1 so far, have already covered most of the OOP aspects that is usually covered in a C++ book. If this was my first language, I would be frightened for sure :)

However, i'm quite sure by looking at the table of contents, that this is some sort of "review" for what's coming.


The way I understand it is that the first 2 two chapters an overview of the language. The subsequent chapters will go into much more depth about what they do and how.

Beginner in Game Development?  Read here. And read here.

 

static bool Equals(List a, List b) {        if (a == null) return b == null;	if (b == null || a.count != b.count) return false;	for (int i = 0; i < a.count; i++) {		if (!object.Equals(a.items, b.items)) {			return false;		}	}}


I'm confused. When does this function return true? I can only see in the first if statement. If a == null, then return b == null. If b == null, then it Equals will return true. Other than that, all I see is this function returning false. Obviously, I'm missing something. What is it?

Beginner in Game Development?  Read here. And read here.

 

Quote: Original post by Alpha_ProgDes
*** Source Snippet Removed ***

I'm confused. When does this function return true? I can only see in the first if statement. If a == null, then return b == null. If b == null, then it Equals will return true. Other than that, all I see is this function returning false. Obviously, I'm missing something. What is it?


Following the logic, it looks like there's a missing "return (true)" right before the end of the method. In fact, in VSC#2005, compiling that would return an error since not all code paths return a value.
Quote: Original post by Alpha_ProgDes
*** Source Snippet Removed ***

I'm confused. When does this function return true? I can only see in the first if statement. If a == null, then return b == null. If b == null, then it Equals will return true. Other than that, all I see is this function returning false. Obviously, I'm missing something. What is it?


It simply won't compile, as there's a path that doesn't end in a return. I think you may assume that return true; needs to be added at the end: if none of the elements are not-equal, then they're all equal, hence the lists are equal.
Quote: Original post by Alpha_ProgDes
Ok. Question. I'm sure someone in this thread touched on this earlier.

*** Source Snippet Removed ***

Is that wrong? Yes, the virtual is left out on purpose because I don't how the compiler or program could choke on this at runtime.


Bar.bleh hides Foo.bleh; If a Bar is assigned to a Foo reference, Bar.bleh will never get called; Foo.bleh will. MSVC#2005 tosses a warning on this as written.
Please answer this question too.

Beginner in Game Development?  Read here. And read here.

 

Quote: Original post by Alpha_ProgDes
Ok. Question. I'm sure someone in this thread touched on this earlier.

*** Source Snippet Removed ***

Is that wrong? Yes, the virtual is left out on purpose because I don't how the compiler or program could choke on this at runtime.


Technically, it's not wrong. The compiler only gives a warning about not using new on the subclass's bleh method.

C# tries to make everything explicit so as to prevent accidents. E.g. I once had a bug in java that was due to the fact that I misspelled a method name and thus would not override the superclass's version of the method. To prevent this, C# insists you make your intentions explicit by adding override to the method's definition.

The compiler will warn you about the bleh-line as an ex-java programmer might think it means overriding bleh. The warning will lead him to investigate and find out that this is not what happens.

(edit: damn you telastyn for making me feel redundant!)

This topic is closed to new replies.

Advertisement