Содержание
- 2. Your First C# Program Our first C# program is a real classic. It does nothing more
- 3. This program sends the simple greeting to the console // Example1_1.cs // This program sends a
- 4. A Closer Look to the strucure of C# program In C#, as in other C-style languages,
- 5. Variables in C# We declare variables in C# using the following syntax: DataType variableName; // or
- 6. Initialization of Variables Can’t do this ! Need to initialize d befor use Would only create
- 7. Variable scope
- 8. Scope clashes for local variables public static i n t Main(){ int j = 20; We
- 9. Scope clashes for fields and local variables class ScopeTest2 { static int j = 20; public
- 10. Constants const int a = 10 0 ; // This value cannot be chang e They
- 11. Statements Programs consist of sequences of C# statements Conditional statements Loops Statements allow us to control
- 12. Conditional statements The if statement One - way if if ([condition]) [code to execute] if ([condition])
- 13. The switch statement switch ([expression to check]) { case [test1]: ... [exit case statement] case [test2]:
- 14. Loops C# provides four different loops The for loop The do … while loop Loops allow
- 15. The for loop Syntax for (int i = 0; i { // Code to loop, which
- 16. Nested loops Example static void Main(string[] args) { // This loop iterates through rows... for (int
- 17. The while loop while ([condition]) { [Code to loop] } Syntax double balance = 100D; double
- 18. The do … while loop The do...while loop is the post-test version of the while loop
- 19. The foreach loop The foreach loop allows us to iterate through each item in a collection.
- 20. Jump statements C# provides the number of statements that allow us to jump to another line
- 21. Classes and Structs Classes and structs are templates form wich we can create objects. Each object
- 22. Classes Members Data members are those members that contain the data for the class – fields,
- 23. Classes Members Fields are any variables associated with the class. We can access these fields using
- 24. Function Members Function members are those members that provide some functionality for manipulating the data in
- 25. Declaring methods The definition of the method consists: method modifiers, the type of return value, the
- 26. Passing parameters to methods class ParameterTest{ s ta t ic void SomeFunction(int[] ints , int i)
- 27. Ref parameters // define method stati c v oid SomeFunction(int[] ints, re f int i) {
- 28. Out parameters // define method stati c v oid SomeFunction(out int i) { i = 100;
- 29. Properties The idea of a property is that it is a method or pair of methods
- 30. To define a property… We use the following syntax: The get accessor takes no parameters and
- 31. To define a property… private string foreNam e; p ublic string ForeName{ get { r eturn
- 33. Скачать презентацию