Advertisement

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

Started by July 01, 2007 12:15 AM
337 comments, last by paulecoyote 17 years, 2 months ago
Quote: Original post by hpjchobbes
Question regarding the base 'object' and boxing/unboxing. Since every type inherits from the base 'object' type, would it be something similar to this?
*** Source Snippet Removed ***

It would be similar, except that the function would have the
override
marker, and I am not sure that those new functions are actually virtual. But you got the right idea.

Quote: Original post by hpjchobbes
After typing this, it seems like object may even be using an interface, like so:
*** Source Snippet Removed ***

You're right, it could derive from interface, but in this instance what would be the point? Nothing else would ever derive from IObject, and object doesn't add any new method to IObject, so there seems to be little reason to do this.

Quote: Original post by hpjchobbes
Based on this, if you inherit a class from a class that implements an interface, does the derived class also have to implement the interface or only if they explicitly state they will implement the interface?

It's not that the derived class has to implement the interface, it already does implement the interface, because the derived class has all of the members of its base class.

Quote: Original post by hpjchobbes
If I understand this correctly, if I 'box' my int to an object {object o = (object)int} then I can only use the members of object, unless I cast (which unboxes or reboxes?)
*** Source Snippet Removed ***

That is correct.

EDIT: Doh! Too late. I am too slow.
Mike Popoloski | Journal | SlimDX
I just wanted to post a little something here with my voice.

First of all, my first language was C++. I have been programming in C++ for about 2 years and and I am not going to lie and say C++ is not hard...it is. Though, I must say I did not find C++ as hard as lots of people have told me it was when I first started to dive into it 2 years ago. Sure, I am still a young C++ programmer though I have hit some of the major topics in C++ that seem to confuse people. Those being Pointers, Operator Overloading, Templates, and many more. I still have a lot of topics to still cover sure. Anyway, I am saying all this to say that I do find the C# Specification a VERY good read. I also must say that I do see where the C# Specification can be a hard read for beginners, as I, a C++ experienced programmer had trouble in a few little places in Chapters 1 and 2. So, I must let it be known that I do find Jeromy's idea of the overview a very good idea.

I can not wait till the next week. I have finished Chapters 1 and 2 and I have answered all of the review questions.

Chad

Advertisement
WOW! Yesterday I read the chapters 1 and 2. Now, I just read ALL the ten pages. OMFG! I have to congratulate you guys, this workshop is really something!

About INDEXERS, I understood the concept but I didn't see any example and I am curious. Can anybody post a class that use an indexer?

Thanks.
XNA Brasil Dev -> http://xnabrasildev.blogspot.com (in portuguese, but I will start to post in english)One Winning Eleven to rule them all!
Quote: Original post by JWalsh
If you've found the above a more human-readable format for learning beginning C#, please let me know. Note, this is again just an overview of the information in week 1. If this format receives enough interest, myself or another tutor will write similar overviews for the remaining chapters. Also, please let me know if the above is detailed enough, not detailed enough, etc...What do you want more of, what do you want less of?

This workshop is really about all of you. If you're not getting what you want, or what you expected from the workshop, please speak up so we know what level we need to cater to. If there's enough interest in this format, I'll begin by completing the information below.

Because C# is not my first programming language, I understand the specification fairly well. However, as I learned C++ (my first programming language) I recall reading tutorials very similar to the overview you've written and finding them much easier to decipher than some of the cryptic books I'd purchased. I believe that (if you can find the time - that must've taken a while) these overviews will help to make topics more understandable for new-comers, especially in these touch-on-everything-but-explain-nothing early chapters, and even for people with some experience, like myself, in more advanced chapters. I believe you would essentially be answering some of the questions before they have to be posted, saving everyone time and trouble.

With that said, I also feel like google is a wonderful resource, and there are plenty of laymen's terms tutorials out there on the net already. Perhaps to save yourself some time, you could cover some topics with a simple hyperlink to an easy to understand tutorial which has already been written. If you can't find one, then go ahead and write the overview on that topic, because it will be extremely helpful. You know the saying - don't re-invent the wheel. I know sometimes these online tutorials don't go into the desired detail, but that is where the specification comes in.

Well that's my two cents, I've run out of time!
Quote: Original post by Coragi
WOW! Yesterday I read the chapters 1 and 2. Now, I just read ALL the ten pages. OMFG! I have to congratulate you guys, this workshop is really something!

About INDEXERS, I understood the concept but I didn't see any example and I am curious. Can anybody post a class that use an indexer?

Thanks.


A very incomplete matrix class.
public class Matrix{    // The indexer    public float this[int row, int col]    {        get        {            return _matrix[row, col];        }        set        {            _matrix[row, col] = value;        }    }    // Uses the indexer    public static Matrix operator +(Matrix a, Matrix b)    {        if ( a.IsSameSize( b ) )        {            float[,] m = new float[a.Height, a.Width];            for ( int i = 0; i != a.Height; ++i )            {                for ( int j = 0; j != a.Width; ++j )                {                    m[i, j] = a[i, j] + b[i, j];                }            }            return new Matrix( m );        }        else        {            throw new InvalidOperationException( "Matrices must be the same size" );        }    }    public Matrix(int rows, int cols)    {        _matrix = new float[rows, cols];    }    private Matrix(float[,] matrix)    {        _matrix = matrix;    }    public int Height    {        get        {            return _matrix.GetLength( 0 );        }    }    public int Width    {        get        {            return _matrix.GetLength( 1 );        }    }    public bool IsSameSize(Matrix other)    {        return this.Width == other.Width && this.Height == other.Height;    }    private float[,] _matrix;}
Ok, little backround on me, I've taken classes on C++ and Java... never taken C#, but I'm looking at snippets of code from the tutorials and I just want a bit of clarification.

Is C# a Hybrid of of sorts of Java and C++? there seems to be aspects of both languages in this one.
Advertisement
Quote: Original post by SamLowry
Quote: Original post by Coragi
WOW! Yesterday I read the chapters 1 and 2. Now, I just read ALL the ten pages. OMFG! I have to congratulate you guys, this workshop is really something!

About INDEXERS, I understood the concept but I didn't see any example and I am curious. Can anybody post a class that use an indexer?

Thanks.


A very incomplete matrix class.
*** Source Snippet Removed ***


Well, this is just what I understood. Thanks a lot. Just one thing, I think an example using an array with just one dimension would be easier to get it. :)
XNA Brasil Dev -> http://xnabrasildev.blogspot.com (in portuguese, but I will start to post in english)One Winning Eleven to rule them all!
Quote: Original post by R1techie
Ok, little backround on me, I've taken classes on C++ and Java... never taken C#, but I'm looking at snippets of code from the tutorials and I just want a bit of clarification.

Is C# a Hybrid of of sorts of Java and C++? there seems to be aspects of both languages in this one.


Sorry, I don't want to create a flame, but what's the point? C# has a lot of things of Java and C++. So what? ehehehehehe :D
XNA Brasil Dev -> http://xnabrasildev.blogspot.com (in portuguese, but I will start to post in english)One Winning Eleven to rule them all!
Quote: Original post by R1techie
Ok, little backround on me, I've taken classes on C++ and Java... never taken C#, but I'm looking at snippets of code from the tutorials and I just want a bit of clarification.

Is C# a Hybrid of of sorts of Java and C++? there seems to be aspects of both languages in this one.


C# is an imperative OO-language using C-based syntax, like java. Some things are done the same, some things are done differently. Know java, and you know 70%-80% of C# I'd say.
I'd like to give you my comments on the overview. This is from the point of view of someone who has been programming for about 2 years in C++ and Python, primarily. I have understood the reference pretty well.

I think that what was lacking the most in the reference was descriptions of the concepts of functions, variables, and other basic programming ideas. Since these are so fundamental, they can be overlooked by anyone with a background in programming, but for a beginner they are necessary. I feel that your overview of Chapter 1 would benefit from describing these in more detail than the reference did. All beginning programming books begin with the analogies of "variables are boxes where you can put things" and what-not. Some description of these is necessary for complete beginners, since they form the building blocks where everything comes off of.

In summary I would think that having the following concepts explained briefly would help:

-Variables
--Declaration
--Allocation
--Assignment
-Functions
--Parameters
--Returning
--Defining a function
--Calling a function

Even just a few sentences on each should prove beneficial.

This topic is closed to new replies.

Advertisement