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 JWalsh
*snip*

(It's good practice according to the Microsoft C# style Guideline to name Properties the same as their data types whenever possible)

*snip*


I searched both MSDN and Google trying to find this style guideline and couldn't find it. I found a few others but I was wondering if you, or anyone else, had a link to this style guide?
-Brandon Blog | Journal
Design Guidelines for Class Library Developers

[Edited by - Washu on July 5, 2007 11:34:10 PM]

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Advertisement
Quote: Original post by Washu
To be specific, each enumeration type is a type of its own, however the underlying storage type (used to hold the values) default to integer. You can actually override the default storage type as such:
*** Source Snippet Removed ***


While we're on this subject why would you ever change the default storage type from int to anther type?

How about them apples?
Hi everyone,

First, I want to say thanks to JWalsh for orchestrating this workshop; it has been very enjoyable and informative so far. Also, thanks to all the tutors for helping out with our questions.

Now, I have some questions regarding the uses of lock and using.

The specification states in section 1.5:
Quote:
The lock statement is used to obtain the mutual-exclusion lock for a given object, execute a statement, and then release the lock.

So, is lock just like a semaphore? Also, I am assuming that the lock is released upon exiting the block following the lock statement.

The using statement is also a little vague in my mind. The specification states this in section 1.5:
Quote:
The using statement is used to obtain a resource, execute a statement, and then dispose of that resource.

The way I translate the bold part of that quote is that the resource is immediately garbage collected upon leaving the associated block, as opposed to waiting for the garbage collector to reclaim the resource at its next convenience. If this is not the case, then what is the point of the using keyword in this context?
Quote: Original post by popcorn
Quote: Original post by Washu
To be specific, each enumeration type is a type of its own, however the underlying storage type (used to hold the values) default to integer. You can actually override the default storage type as such:
*** Source Snippet Removed ***

While we're on this subject why would you ever change the default storage type from int to anther type?

In general: You shouldn't need to. However, when using pinvoke, you may encounter cases where constants were used of a particular size (WORD/SHORT in the Win32 case) that are best represented as an enumeration. In those cases, you can simply alter your enumeration to use the appropriate storage type. You can also use this data when serializing information to be packed into a network packet.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Quote: Original post by sebas417
Hi everyone,

First, I want to say thanks to JWalsh for orchestrating this workshop; it has been very enjoyable and informative so far. Also, thanks to all the tutors for helping out with our questions.

Now, I have some questions regarding the uses of lock and using.

The specification states in section 1.5:
Quote:
The lock statement is used to obtain the mutual-exclusion lock for a given object, execute a statement, and then release the lock.

So, is lock just like a semaphore? Also, I am assuming that the lock is released upon exiting the block following the lock statement.

Actually, it's just an implicit call to Monitor.Enter and Monitor.Exit, analogous code would be:
// lock(o) { ... }try {    System.Threading.Monitor.Enter(o);    // ...} finally {    System.Threading.Monitor.Exit(o);}

Quote:
The using statement is also a little vague in my mind. The specification states this in section 1.5:
Quote:
The using statement is used to obtain a resource, execute a statement, and then dispose of that resource.

The way I translate the bold part of that quote is that the resource is immediately garbage collected upon leaving the associated block, as opposed to waiting for the garbage collector to reclaim the resource at its next convenience. If this is not the case, then what is the point of the using keyword in this context?

Using is actually:
//Given:public class Rawr : IDisposable {	public void Dispose() {		Dispose(true);		GC.SuppressFinalize(this);	}	protected virtual void Dispose(bool disposing) {		if (disposing) {			//release manage and unmanaged resources			Console.WriteLine("Disposing of managed resources");		}	}	~Rawr() {		Dispose(false);	}}//then: using(Rawr r = new Rawr()) { ... } would beRawr r = null;try {	r = new Rawr();	// ...} finally {	if(r != null)		((IDisposable)r).Dispose();}

As such, it does not affect garbage collection at all. You can use using and the IDisposable pattern to allow yourself the ability to release unmanaged and managed resources in a deterministic manner (remember, the GC is non-deterministic (well, actually it is deterministic if you knew all the input variables before hand but...)).

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Advertisement
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.


I feel like I'm about average. I get most of this, but the more advanced stuff in OOP is something I need to examine a bit more before I understand it. I think your working examples are great, and for me, using RPG game elements in those examples really adds that exstra spark of interest which makes me go though it and modify it until i really understand it.

I really think summaries and working examples showing the more important stuff helps a lot of us here to reinforce our knowledge of what we just learned and make sure it really sticks. Reading theory of how this and that benefits us can be hard unless we actually see it in action.

I think that those new to C# and programming in general would benefit with some exercises where they would have to write some code and get familiar with the basic concepts of variables, operators, loops etc.. If you're going to extend this week with another week, maybe we could create something like Hangman or something..?

It probably takes a lot more of your free time, but that's why you're here, right? ;)
Quote: Original post by Nunyah
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.


I feel like I'm about average. I get most of this, but the more advanced stuff in OOP is something I need to examine a bit more before I understand it. I think your working examples are great, and for me, using RPG game elements in those examples really adds that exstra spark of interest which makes me go though it and modify it until i really understand it.

I really think summaries and working examples showing the more important stuff helps a lot of us here to reinforce our knowledge of what we just learned and make sure it really sticks. Reading theory of how this and that benefits us can be hard unless we actually see it in action.

I think that those new to C# and programming in general would benefit with some exercises where they would have to write some code and get familiar with the basic concepts of variables, operators, loops etc.. If you're going to extend this week with another week, maybe we could create something like Hangman or something..?


I pretty much agree with everything you said, Nunyah.

The Q&A, opinions, and example code has probably been the most beneficial part for me so far. I'm looking forward to solving some exercise problems and banging my head against compiler errors.
-Brandon Blog | Journal
Thank you, TheTroll and paulecoyote.
Sorry if my english is not good, is not my native language, by the way feel free to talk to me in spanish if you want. :P

I was reading Chapter 2 and the last part talks about pre-processor directives, why and when do I need to use them??

This topic is closed to new replies.

Advertisement