🎉 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 - 4) - Beginners

Started by
91 comments, last by CalebGorde 12 years, 10 months ago
I think its great that you're using game-oriented code examples to explain these concepts. Please keep doing that. And thanks for your hard work, its very much appreciated.
Advertisement
Love the idea of breaking the threads apart. Alot of information in the other thread was geared towards intermediate to advanced programmers IMO. Having to search through it all to attempt to find an answer to a question that I posted was a bit tedious. I think as we get a little further along, where we are actually coding, maybe the summaries will not be needed. Although with these two initial chapters, and the breadth of data contained, I am glad jwalsh did that. It did help me to get a little better grasp of the text.

Just for inspiration for some of you other budding programmers out there, this newb is 35 (pushing 36) years old. What's that old saying? You cant teach an old dog new tricks? Hahahahha!!! We will see about that. When it comes time to complete that final project, I hope to see all of you right there with me!!

Thanks,

Shawn

*Edit* - BTW, if anyone around here games, or uses Teamspeak, my clan and I have a teamspeak server. If anyone is interested in the IP or our clans website, shoot me a PM. Maybe we can work through the workshop together utilizing TS (Teamspeak) to overcome some hurdles....just a thought.
No one has anymore beginning C# questions? I'll post more of my overview this weekend.

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Quote: Original post by JWalsh
No one has anymore beginning C# questions? I'll post more of my overview this weekend.

Cheers!


I think your overview answered any questions dealing with the subjects you've written so far, and people are just waiting for the rest of it before they go asking.
Thank you JWalsh for taking the time to run the workshop. I've always wanted to program but procrastination usually gets the better of me. If I do have any questions I will be sure to ask.
Chapter 1 & 2 Review Questions

Greetings everyone. Since it's Friday I wanted to take a moment to provide to you the answers I had when writing the review questions for this week. Please look over the following answers and make sure it matches with yours. If it doesn't and you're confused about why not, please post your questions here or in in the advanced thread for Week 1.

  1. What is component-oriented programming?

  2. Contemporary software design increasingly relies on software components in the form of self-contained and self-describing packages of functionality

  3. What are the keys to software components in C#?

  4. Key to such components is that they present a programming model with properties, methods, and events; they have attributes that provide declarative information about the component; and they incorporate their own documentation

  5. What is Garbage Collection?

  6. Garbage collection automatically reclaims memory occupied by unused objects;

  7. What is exception Handling?

  8. exception handling provides a structured and extensible approach to error detection and recovery;

  9. What benefits do type safety provide you in C#?

  10. design of the language makes it impossible to have uninitialized variables, to index arrays beyond their bounds, or to perform unchecked type casts.

  11. What is a unified type system?

  12. All C# types, including primitive types such as int and double, inherit from a single root object type.

  13. What are the benefits of a unified type system?

  14. all types share a set of common operations, and values of any type can be stored, transported, and operated upon in a consistent manner.

  15. What's the purpose of namespaces?

  16. Namespaces provide a hierarchical means of organizing C# programs and libraries.

  17. What directive allows unqualified use of the members of a namespace?

  18. The 'using' directive.

  19. What is the entry point of a C# Console application?

  20. A static method named "main."

  21. What's the name of the C# Runtime libraries?

  22. The .NET Framework Library

  23. What are the key organizational concepts in C#?

  24. Programs, namespaces, types, members, and assemblies.

  25. What two things do C# assemblies contain and what form are they in?

  26. Executable code in the form of Intermediate Language and symbolic information in the form of metadata

  27. What happens to the IL instructions just before the code is executed?

  28. It is converted into processor-specific code by the JIT compiler of the .NET CLR.

  29. When are forward decelerations needed in C#?

  30. Never.

  31. What are the two kinds of variable types in C# what's the difference?

  32. Valye types and reference types. Value types store data directly, reference types store references to their data.

  33. How are C#'s value types subdivided?

  34. simple types, enum types, and struct types.

  35. How are C#'s reference types subdivided?

  36. Class types, interface types, array types, and delegate types.

  37. What is the encoding of a C# character, and how much memory does a single character require?

  38. Unicode encoding. It requires 16-bits.

    ####
  39. What are the sizes of each of the Simple Types, and their range of values?


  40. Which 5 categories of C# types are user-definable types?

  41. class, struct, interface, enum, and delegate.

  42. Give an overview of each of the 5 types.

  43. A class type defines a data structure that contains data members (fields) and function members (methods, properties, and others). Class types support inheritance and polymorphism, mechanisms whereby derived classes can extend and specialize base classes.

    A struct type is similar to a class type in that it represents a structure with data members and function members. However, unlike classes, structs are value types and do not require heap allocation. Struct types do not support user-specified inheritance, and all struct types implicitly inherit from type object.

    An interface type defines a contract as a named set of function members. A class or struct that implements an interface must provide implementations of the interface’s function members. An interface may inherit from multiple base interfaces, and a class or struct may implement multiple interfaces.

    An enum type is a distinct type with named constants. Every enum type has an underlying type, which must be one of the eight integral types. The set of values of an enum type is the same as the set of values of the underlying type.

    A delegate type represents references to methods with a particular parameter list and return type. Delegates make it possible to treat methods as entities that can be assigned to variables and passed as parameters. Delegates are similar to the concept of function pointers found in some other languages, but unlike function pointers, delegates are object-oriented and type-safe.
  44. What is "boxing" and "unboxing"

  45. The process of casting a C# value type to an object.

  46. What are expressions?

  47. Expressions are constructed from operands and operators

  48. What is the relationship between operators and operands in an expression?

  49. Operators tell what operation to perform on the operands.

  50. What is an operator's precedence?

  51. A rule which governs the order in which the operator is evaluated relative to other operators.

  52. What is operator overloading?

  53. Operator overloading permits user-defined operator implementations to be specified for operations where one or both of the operands are of a user-defined class or struct type.

  54. What are the different kinds of C# statements, and what do they do??

  55. Blocks - Allows multiple other statements in place of a single statements
    Decelerations - declare variables and constants
    Expressions - Evaluate an expression.
    Selection - Also called branching, changes the flow of execution
    Iteration - Similar to branching, allows execution of the same code repeatedly with some variance
    Jump - Similar to branching, changes the scope of execution
    Try...catch - Used to catch exceptions
    Checked/unchecked - Used for checking underflow and overflow in integral types
    Lock - Use for mutually exclusive locks of data for thread safety
    using - use to temporarily obtain resources and dispose of them.

  56. What is a class?

  57. A class is a data structure that combines state (fields) and actions (methods and other function members) in a single unit.

  58. Create an example class named Character. Dont worry about members, methods, or properties

  59. public class Character
    {

    }

  60. What operator is used to create a new instance of a class? What's the syntax to create a Character object?

  61. The new operator
    Character myCharacter = new Character();

  62. What are the different types of members of a class?


  63. Constants - The constant values associated with the class
    Fields - The variables of the class
    Methods - The computations and actions that can be performed by the class
    Properties - The actions associated with reading and writing named properties of the class
    Indexers - The actions associated with indexing instances of the class like an array
    Events - The notifications that can be generated by the class
    Operators - The conversions and expression operators supported by the class
    Constructors - The actions required to initialize instances of the class or the class itself
    Destructors - The actions to perform before instances of the class are permanently discarded
    Types - The nested types declared by the class

  64. What are the 5 types of Accessibility used on a class's members?


  65. public - Access not limited
    protected - Access limited to this class and classes derived from this class
    internal - Access limited to this program
    protected internal -Access limited to this program and classes derived from this class
    private Access limited to this class

  66. What does inheritance mean?

  67. Inheritance means that a class implicitly contains all members of its base class, except for the constructors of the base class

  68. What is a field?

  69. A field is a variable that is associated with a class or with an instance of a class.

  70. What is the difference between a static and non-static field?

  71. A static field has exactly one memory storage location, which is shared by all instances of a class. non-static is a unique
    memory address for each instance.

  72. What is a method of a class?

  73. A method is a member that implements a computation or action that can be performed by an object or class.

  74. What's the difference between static and non-static methods?

  75. Static methods are accessible from the class, while non-static are accessible from the instances of the class, or "objects."

  76. What are parameters?

  77. list of arguments, which represent values or variable references passed to the method

  78. What are return types?

  79. specifies the type of the value computed and returned by the method

  80. What does a signature of a method consist of?

  81. The signature of a method consists of the name of the method and the number, modifiers, and types of its parameters. The signature of a method does NOT include the return type.

  82. What are the 4 types of parameters and how are they used?

  83. Value, reference, output, and arrays. Value is for input parameters. Reference parameters are used for both input and output. Output parameters are used simply for outgoing parameter passing. Parameter arrays allow a variable number of arguments to be passed into the method.

  84. What is a static method?

  85. A method declared with a static modifier. It does not operaote on a specific instance of a class, and can only access static members.

  86. What is an instance method?

  87. Any method created without the static modifier. It operates on specific instance of the class, and can access both static and non-static members.

  88. What's the difference between a virtual and non-virtual method?

  89. When a virtual method is invoked, it's runtime type for the instance is invoked. For a non-virtual method, the compile-time type is invoked.

  90. What does it mean to override a virtual method?

  91. The method overrides an inherited virtual method with the same signature, thus providing a new implementation for that method.

  92. What is an abstract method and when is it permitted?

  93. A method with no implementation. It is only permitted in classes also declared abstract.

  94. What is method overloading?

  95. Method overloading permits multiple methods in the same class to have the same name, so long as they have unique signatures.

  96. What is the difference between an instance constructor and a static constructor?

  97. Instance constructors are called when an object is created, to initialize the object. Static constructors are called by the CLR when a class is loaded, and is used to initialize the class itself.

  98. What is the primary difference between properties and fields?

  99. Properties do not denote storage locations, and instead provide accessors which specify the statements to be executed when their values are read or written to.

  100. How do you make a property read-only?

  101. Dont provide a set method.

  102. What is an indexer?

  103. An indexer is a member that enables object to be indexed in the same way as an array. It is declared like a property, except the name is always "this" followed by a parameter list written between square brackets.

  104. What is an event, and what is true of it's type?

  105. An event is a member that enables a class or object to provide notifications. The type must always be a delegate.

  106. What are event handlers?

  107. Event handlers are methods attached to an event using the += operator and removed with the -= operator.

  108. What is a class operator?

  109. Its a member that defines (re-defines) the meaning of applying a particular expression operator to instances of the class.

  110. What is a destructor?

  111. A member that implements the actions required to destruct an instance of a class - specifically non-garbage collected member data.

  112. What's the main difference between classes and structs?

  113. Structs are value types instead of the reference types, and can be created on the stack, rather than the heap. A struct directly stores the data of the struct, while a class stores a reference to an object. Also, structs do not support inheritance.

  114. What is an array?

  115. An array is a data structure that contains a number of variables of the same type that are accessed through computed indices.

  116. What is an array initializer?

  117. A way of initializing the values within an array during construction of the array.

  118. What is an interface, and what can it contain?

  119. An interface defines a contract that can be implemented by classes and structs. An interface can contain methods, properties, events, and indexers.

  120. What are enums?

  121. enums are a value type which contain a set of named, symbolic constants.

  122. What is an enum's underlying type?

  123. All enums have an underlying integral type. Those that are not specified have default underlying type of 'int'.

  124. What is a delegate?

  125. A delegate represents references to methods with a particular parameter list and return type. Delegates make it possible to treat methods as variables which can be assigned and passed as parameters.

  126. What is the purpose of attributes?

  127. To allow user-defined types of declarative information that can be attached to program entities and retrieved at run-time.

  128. What is a compilation unit in C#?

  129. It's a source file

  130. What are the 3 steps in compiling a program?

  131. 1. Transformation
    2. Lexical Analysis
    3. Syntatic Analysis

  132. What encoding are C# files in? ie. ASCII?

  133. Unicode

  134. What is the purpose of lexical grammar?

  135. It defines how Unicode characters are combined to form line terminators, white space, comments, tokens, and pre-processing directives.

  136. What is the purpose of syntactic grammar?

  137. Defines how the tokens resulting from the lexical grammar are combined to form C# programs.

  138. What is contained within the first line of a grammar rule?

  139. The non-terminal symbol being defined, followed by a colon.

  140. When you see the suffix "opt" in a grammar rule, what does it mean?

  141. It means the previous term is optional.

  142. What are the five basic elements that make up the structure of a C# source file?

  143. Line terminators, white space, comments, tokens, and pre-processing directives.

  144. Which of the 5 elements of a C# source file are relevant to the syntax of a C# file?

  145. The tokens.

  146. What do line terminators do?

  147. divide the characters of C# source files into lines.

  148. What are the two forms of comments supported by C#, give examples.

  149. Single line comments, which start with // and comment out everything else on the line...and...
    Delimited comments, which are anything between /* and */, even spanning multiple lines.

  150. What are the 5 types of tokens?

  151. Identifiers, Keywords, literals, operators, and punctuators.

  152. List ALL of the C# keywords

  153. abstract	as		base		bool		breakbyte		case		catch		char		checkedclass		const		continue	decimal		defaultdelegate	do		double		else		enumevent		explicit	extern		false		finallyfixed		float		for		foreach		gotoif		implicit	in		int		interfaceinternal	is		lock		long		namespacenew		null		object		operator	outoverride	params		private		protected	publicreadonly	ref		return		sbyte		sealedshort		sizeof		stackalloc	static		stringstruct		switch		this		throw		truetry		typeof		uint		ulong		uncheckedunsafe		ushort		using		virtual		voidvolatile	while

  154. What is a literal, and what are the 6 types of literals?

  155. A source code representation of an actual value.
    boolean
    integer
    real
    character
    string
    null

  156. Give an example of each type of literal.

  157. true
    200
    200.23
    'c'
    "Hello, World"
    null

  158. What is a verbatim literal string, and how is it created?

  159. A verbatim literal is one with a @ at the beginning, and in a verbatim string, escape characters are not interpreted.

  160. What are the possible Pre-processing directive, what is their function, and what is their intended use?

  161. #define, #undef - defining and undefing symbols
    #if, #elif, #else, #endif controling conditional compilation based on the existance of defined symbols
    #line changing the line number and file name of source.
    #error and #warning, used to generate compile-time warnings and errors
    #region and #endregion used to group lines of source code for a programmer.
Chapter 1 & 2 Exercises

As this week is largely an overview of the entire language and doesnt go into significant enough detail to warrant a large number of exercises, we'll keep it simple for this week. Next week, however...[wink]

1. Write a program which outputs your name to the console.
using System;class Hello{    static void Main()     {	Console.WriteLine("My name is Jeromy Walsh");    }}
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Beginner Question.

I have visual studio.net 2005 Standard Ed.

Ok I did all excersies no bugs. I build than test it.. It pops up with command console than disappears in like 1/2 a second.. How do I have it stay?


I remember in c++ I had something 0;

Thanks

P.S Good work. Keep it up :-)

-Zac Karpinski
Quote: Original post by zKarp
Beginner Question.

I have visual studio.net 2005 Standard Ed.

Ok I did all excersies no bugs. I build than test it.. It pops up with command console than disappears in like 1/2 a second.. How do I have it stay?


I remember in c++ I had something 0;

Thanks

P.S Good work. Keep it up :-)

-Zac Karpinski


I believe ctrl-f5 runs the app and keeps the console window open. Failing that, add System.Console.ReadKey(); before your return statement (if you have one).

Quote: Original post by Andorien
I believe ctrl-f5 runs the app and keeps the console window open. Failing that, add System.Console.ReadKey(); before your return statement (if you have one).


Thanks the ctrl-f5 works.

and yea return 0; is what i used in C++. :-) *I think*

Thanks again Andorien

-Zac Karpinski

Quote: Original post by Exershio
Is it just me or does C++ seem a hell of a lot easier? I started learning C++ a couple months ago, and have a firm grasp on the language, but jeez, C# is confusing the hell out of me. It may be just the spec we are reading.

I'm going to reread Chapter 1 again right now and see if it helps to understand it.


IMO C# looks a lot easier than C++. But that may be because i have a Java background.

C# seems to be more Java-oriented than C++ oriented, am I right? (I'n not a C++ buff, so I can't judge)

I mean:

C#:
1: class HelloWorldProgram2: {3:     static void Main()4:     {5:         System.Console.WriteLine("Hello World");6:     }7: }  	


Java:
class HellowWorldProgram {    public static void main(String[] args)    {        System.out.println("Hello World");    }}

"Anyone who has never made a mistake has never tried anything new." - Albert Einstein

This topic is closed to new replies.

Advertisement