This document provides an overview of key concepts in C#, including similarities to Java, common C# language features, classes vs. structs, interfaces, abstract classes, and class internals like fields, properties, modifiers, and conversion operators. Some key points:
- C# and Java share similarities like all classes being objects, a similar compilation/runtime model using a virtual machine, and heap-based allocation using "new".
- C# supports common features like namespaces, classes, structs, enums, interfaces, and control statements. Classes are reference types while structs are value types.
- Interfaces define contracts without implementation, while abstract classes can contain some implementation but cannot be instantiated.
The document discusses C# and .NET programming concepts. It states that C# is the primary language for .NET development and provides an overview of key C# concepts like variables, data types, operators, control flow statements, classes, objects, inheritance, polymorphism, and the differences between classes and structures. It also covers arrays, namespaces, properties, and common .NET modifiers like public, private, and static.
C# programs use namespaces and classes. A class defines methods and variables. C# supports inheritance, interfaces, structs, and enums. The main method runs code. Common data types include primitive types like int and reference types like string. C# can read input, perform math operations, and conditionally execute code using if/else statements. Methods can pass parameters by value or reference.
The document outlines a lecture plan for object oriented programming. It covers topics like structures and classes, function overloading, constructors and destructors, operator overloading, inheritance, polymorphism, and file streams. It provides examples to explain concepts like structures, classes, access specifiers, friend functions, and operator overloading. The document also includes questions for students to practice these concepts.
C# programs use the .cs file extension and consist of namespaces, classes, and methods. A basic C# program defines a Main method within a class, where code is written. Classes can inherit from other classes and implement interfaces. The document provides an overview of basic C# concepts like data types, strings, enums, structures, and passing parameters by value and reference. It also demonstrates how to get input, write output, and use common .NET classes.
This document provides an overview and introduction to the C# programming language and .NET framework. It covers key C# concepts like its syntax, type system, classes, interfaces, collections and more. It also discusses .NET concepts like assemblies, garbage collection, and tools for C# development like Visual Studio.NET. The document contains sample C# code and concludes with a Hello World example to demonstrate basic C# syntax.
C++ is an object-oriented programming language that is an extension of C. It was developed in the early 1980s by Bjarne Stroustrup at Bell Labs. C++ supports concepts like inheritance, polymorphism, and encapsulation that make it suitable for large, complex programs. Inheritance allows classes to inherit properties from parent classes. Polymorphism is the ability to process objects of different types in the same way. Encapsulation combines data and functions that operate on that data within a single unit, hiding implementation details. File input/output in C++ can be handled through streams like ifstream for input and ofstream for output.
Dart is a new open source programming language created by Google. It is a simple object-oriented language with optional static typing that compiles to JavaScript. Dart aims to make web development easier by improving on JavaScript syntax and providing better tools like an optional type system, classes, and isolates for concurrency. It is not meant to replace JavaScript but to make web development more productive across platforms.
C# is similar to C++ but easier to use, as it does not support pointers, multiple inheritance, header files or global variables. Everything must live within a class or struct. The basic syntax will be familiar to C++ programmers. Key features include properties, interfaces, foreach loops, and delegates for event handling. Properties allow custom getter and setter logic and are preferred over public fields. Delegates provide a type-safe way to link methods, and events build on this to prevent issues with multicast delegates. Generics and assemblies are analogous to C++ templates and deployment units.
The document provides an overview of key Java concepts including:
1) Classes and methods define the structure and behaviors of objects in Java. Data types include primitives and object references.
2) Control statements like if/else and loops operate similarly to other languages like C++. Object-oriented concepts include inheritance, polymorphism, and encapsulation.
3) Interfaces define common behaviors without implementation, while abstract classes can contain abstract and implemented methods. The Java Virtual Machine executes Java bytecode making programs platform independent.
This document provides an overview of the Dart programming language. Dart is a language and tool ecosystem for building complex web apps in teams. It runs in the browser and on servers. Key points covered include: Dart is optionally typed and runs in a virtual machine; the goals of Dart including performance, familiarity, and flexibility; and libraries like dart:html for DOM manipulation and dart:io for server-side functionality. The presentation encourages attendees to get involved in the technical preview to help shape the future of Dart.
The document provides an overview of advanced features in the C# programming language, including interfaces, classes, structs, delegates, events, and other topics. It begins with learning objectives and an agenda, then reviews key object-oriented concepts. The remainder of the document describes interfaces, classes, structs, methods, properties, indexers, constants, fields, and other features in more detail.
Writing code that writes code - Nguyen LuongVu Huy
?
¡°The Pragmatic Programmer¡± admonished us all to ¡°write code that writes code¡±: use code generators to increase productivity and avoid duplication. The language communities have clearly caught on, as more and more frameworks generate code at compile time: Project Lombok, Google Auto, and more.
This session reviews these approaches including examples of how and why we¡¯d want to do this.
We will see newest Java language tools, write our own AST tranform and look at some amazing libraries based on these techniques.
Bio: Nguyen Luong is a senior java technical lead at Ekino Vietnam. He likes to research new technologies and solve security challenges.
¡°The Pragmatic Programmer¡± admonished us all to ¡°write code that writes code¡±: use code generators to increase productivity and avoid duplication. The language communities have clearly caught on, as more and more frameworks generate code at compile time: Project Lombok, Google Auto, and more.
This session reviews these approaches including examples of how and why we¡¯d want to do this.
We will see newest Java language tools, write our own AST tranform and look at some amazing libraries based on these techniques.
Bio: Nguyen Luong is a senior java technical lead at Ekino Vietnam. He likes to research new technologies and solve security challenges.
Back-2-Basics: .NET Coding Standards For The Real World (2011)David McCarter
?
Revamped for 2011 (90% new material), this session will guide any level of programmer to greater productivity by providing the information needed to write consistent, maintainable code. Learn about project setup, assembly layout, code style, defensive programming and much, much more. Code tips are included to help you write better, error free applications. Lots of code examples in C# and VB.NET. This session is based off my latest book, David McCarter's .NET Coding Standards.
The document discusses object-oriented programming concepts like classes, objects, member functions, data members, constructors, and encapsulation. It explains that a class defines the structure and behavior of objects, with data members representing attributes and member functions representing behaviors. Constructors initialize an object's data when it is created. Encapsulation protects data by making it private and only accessible through public member functions.
- Classes are blueprints for objects in C#. Objects are instances of classes. Classes contain data fields, methods, and other members.
- There are different access modifiers like public, private, and protected that control access to class members. Constructors initialize new objects, and destructors perform cleanup when objects are destroyed.
- Inheritance allows classes to inherit members from base classes. Polymorphism allows classes to share common interfaces while providing different implementations. Interfaces define contracts without implementation, while abstract classes can contain partial implementations.
- Encapsulation hides implementation details within a class. Abstraction exposes only necessary details to users through public interfaces. Extension methods can add methods to existing types without creating new derived types.
This document provides an overview of key object-oriented programming concepts including classes and objects, inheritance, encapsulation, polymorphism, interfaces, abstract classes, and design patterns. It discusses class construction and object instantiation. Inheritance is described as both exposing implementation details and potentially breaking encapsulation. Composition is presented as an alternative to inheritance. The document also covers method overriding, overloading, and duck typing as forms of polymorphism. Finally, it briefly introduces common design principles like SOLID and patterns like delegation.
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...yazad dumasia
?
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and Inheritance , Exploring the Base Class Library -, Debugging and Error Handling , Data Types full knowledge about basic of .NET Framework
This document provides an overview of the Dart programming language. It discusses why Dart was created by Google, its key design goals around flexibility, familiarity, and performance. It also summarizes Dart's main features like optional typing, classes and interfaces, libraries, and futures. The document encourages attendees to get involved in the technical preview by visiting the Dart website, joining mailing lists, and using online resources.
Defining Simple Classes
Using Own Classes and Objects
Access Modifiers
Constructors and Initializers
Defining Fields
Defining Properties, Getters and Setters
Defining Methods
Exercises: Defining and Using Own Classes
Framework Design Guidelines For Brussels Users Groupbrada
?
This document summarizes 10 years of experience with framework design guidelines from Microsoft. It discusses core principles of framework design that have remained the same over 10 years, such as layering dependencies and managing types. It also outlines new advances like test-driven development, dependency injection, and tools for dependency management and framework design. The document concludes by emphasizing that framework design principles have stayed consistent while new techniques have emerged to help implement those principles.
Interfaces in Java allow classes to define common behaviors without inheritance. An interface defines abstract methods and constants but provides no implementation. A class implements an interface by providing method bodies for the abstract methods. Interfaces allow for multiple inheritance of behaviors. Default methods were added in Java 8 to allow interfaces to define method implementations for existing classes to optionally use.
The document discusses exception handling in C# programs. It explains that exceptions are errors that occur during program execution. The C# try, catch, and finally keywords are used to handle exceptions. The try block contains code that might cause exceptions. The catch block handles specific exception types. The finally block contains cleanup code that always executes. Built-in exceptions like DivideByZeroException are part of the .NET Framework. Exception handling prevents program crashes and allows graceful handling of errors.
The document discusses clean code principles such as writing code for readability by other programmers, using meaningful names, following the DRY principle of not repeating yourself, and focusing on writing code that is maintainable and changeable. It provides examples of clean code versus less clean code and emphasizes that code is written primarily for human consumption by other programmers, not for computers. The document also discusses principles like the Single Responsibility Principle and the Boy Scout Rule of leaving the code cleaner than how you found it. It questions how to measure clean code and emphasizes the importance of writing tests for code and refactoring legacy code without tests.
The document provides an overview of basic C++ concepts including:
- C++ was developed as an extension of the C language and can be coded in an object-oriented or C-style.
- Keywords were added to support object-orientation, exceptions, and other features.
- Pointers in C++ store the address of a variable in memory.
- Blocks allow code sections to have their own local variables with minimized scope.
- Binding refers to converting functions/variables to machine addresses, which can be static/early or dynamic/late.
- Variables are statically scoped in C++ and type checking is done at compile-time rather than run-time.
- Most C++
GDG on Campus Monash hosted Info Session to provide details of the Solution Challenge to promote participation and hosted networking activities to help participants find their dream team
More Related Content
Similar to CSharp presentation and software developement (20)
C# is similar to C++ but easier to use, as it does not support pointers, multiple inheritance, header files or global variables. Everything must live within a class or struct. The basic syntax will be familiar to C++ programmers. Key features include properties, interfaces, foreach loops, and delegates for event handling. Properties allow custom getter and setter logic and are preferred over public fields. Delegates provide a type-safe way to link methods, and events build on this to prevent issues with multicast delegates. Generics and assemblies are analogous to C++ templates and deployment units.
The document provides an overview of key Java concepts including:
1) Classes and methods define the structure and behaviors of objects in Java. Data types include primitives and object references.
2) Control statements like if/else and loops operate similarly to other languages like C++. Object-oriented concepts include inheritance, polymorphism, and encapsulation.
3) Interfaces define common behaviors without implementation, while abstract classes can contain abstract and implemented methods. The Java Virtual Machine executes Java bytecode making programs platform independent.
This document provides an overview of the Dart programming language. Dart is a language and tool ecosystem for building complex web apps in teams. It runs in the browser and on servers. Key points covered include: Dart is optionally typed and runs in a virtual machine; the goals of Dart including performance, familiarity, and flexibility; and libraries like dart:html for DOM manipulation and dart:io for server-side functionality. The presentation encourages attendees to get involved in the technical preview to help shape the future of Dart.
The document provides an overview of advanced features in the C# programming language, including interfaces, classes, structs, delegates, events, and other topics. It begins with learning objectives and an agenda, then reviews key object-oriented concepts. The remainder of the document describes interfaces, classes, structs, methods, properties, indexers, constants, fields, and other features in more detail.
Writing code that writes code - Nguyen LuongVu Huy
?
¡°The Pragmatic Programmer¡± admonished us all to ¡°write code that writes code¡±: use code generators to increase productivity and avoid duplication. The language communities have clearly caught on, as more and more frameworks generate code at compile time: Project Lombok, Google Auto, and more.
This session reviews these approaches including examples of how and why we¡¯d want to do this.
We will see newest Java language tools, write our own AST tranform and look at some amazing libraries based on these techniques.
Bio: Nguyen Luong is a senior java technical lead at Ekino Vietnam. He likes to research new technologies and solve security challenges.
¡°The Pragmatic Programmer¡± admonished us all to ¡°write code that writes code¡±: use code generators to increase productivity and avoid duplication. The language communities have clearly caught on, as more and more frameworks generate code at compile time: Project Lombok, Google Auto, and more.
This session reviews these approaches including examples of how and why we¡¯d want to do this.
We will see newest Java language tools, write our own AST tranform and look at some amazing libraries based on these techniques.
Bio: Nguyen Luong is a senior java technical lead at Ekino Vietnam. He likes to research new technologies and solve security challenges.
Back-2-Basics: .NET Coding Standards For The Real World (2011)David McCarter
?
Revamped for 2011 (90% new material), this session will guide any level of programmer to greater productivity by providing the information needed to write consistent, maintainable code. Learn about project setup, assembly layout, code style, defensive programming and much, much more. Code tips are included to help you write better, error free applications. Lots of code examples in C# and VB.NET. This session is based off my latest book, David McCarter's .NET Coding Standards.
The document discusses object-oriented programming concepts like classes, objects, member functions, data members, constructors, and encapsulation. It explains that a class defines the structure and behavior of objects, with data members representing attributes and member functions representing behaviors. Constructors initialize an object's data when it is created. Encapsulation protects data by making it private and only accessible through public member functions.
- Classes are blueprints for objects in C#. Objects are instances of classes. Classes contain data fields, methods, and other members.
- There are different access modifiers like public, private, and protected that control access to class members. Constructors initialize new objects, and destructors perform cleanup when objects are destroyed.
- Inheritance allows classes to inherit members from base classes. Polymorphism allows classes to share common interfaces while providing different implementations. Interfaces define contracts without implementation, while abstract classes can contain partial implementations.
- Encapsulation hides implementation details within a class. Abstraction exposes only necessary details to users through public interfaces. Extension methods can add methods to existing types without creating new derived types.
This document provides an overview of key object-oriented programming concepts including classes and objects, inheritance, encapsulation, polymorphism, interfaces, abstract classes, and design patterns. It discusses class construction and object instantiation. Inheritance is described as both exposing implementation details and potentially breaking encapsulation. Composition is presented as an alternative to inheritance. The document also covers method overriding, overloading, and duck typing as forms of polymorphism. Finally, it briefly introduces common design principles like SOLID and patterns like delegation.
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...yazad dumasia
?
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and Inheritance , Exploring the Base Class Library -, Debugging and Error Handling , Data Types full knowledge about basic of .NET Framework
This document provides an overview of the Dart programming language. It discusses why Dart was created by Google, its key design goals around flexibility, familiarity, and performance. It also summarizes Dart's main features like optional typing, classes and interfaces, libraries, and futures. The document encourages attendees to get involved in the technical preview by visiting the Dart website, joining mailing lists, and using online resources.
Defining Simple Classes
Using Own Classes and Objects
Access Modifiers
Constructors and Initializers
Defining Fields
Defining Properties, Getters and Setters
Defining Methods
Exercises: Defining and Using Own Classes
Framework Design Guidelines For Brussels Users Groupbrada
?
This document summarizes 10 years of experience with framework design guidelines from Microsoft. It discusses core principles of framework design that have remained the same over 10 years, such as layering dependencies and managing types. It also outlines new advances like test-driven development, dependency injection, and tools for dependency management and framework design. The document concludes by emphasizing that framework design principles have stayed consistent while new techniques have emerged to help implement those principles.
Interfaces in Java allow classes to define common behaviors without inheritance. An interface defines abstract methods and constants but provides no implementation. A class implements an interface by providing method bodies for the abstract methods. Interfaces allow for multiple inheritance of behaviors. Default methods were added in Java 8 to allow interfaces to define method implementations for existing classes to optionally use.
The document discusses exception handling in C# programs. It explains that exceptions are errors that occur during program execution. The C# try, catch, and finally keywords are used to handle exceptions. The try block contains code that might cause exceptions. The catch block handles specific exception types. The finally block contains cleanup code that always executes. Built-in exceptions like DivideByZeroException are part of the .NET Framework. Exception handling prevents program crashes and allows graceful handling of errors.
The document discusses clean code principles such as writing code for readability by other programmers, using meaningful names, following the DRY principle of not repeating yourself, and focusing on writing code that is maintainable and changeable. It provides examples of clean code versus less clean code and emphasizes that code is written primarily for human consumption by other programmers, not for computers. The document also discusses principles like the Single Responsibility Principle and the Boy Scout Rule of leaving the code cleaner than how you found it. It questions how to measure clean code and emphasizes the importance of writing tests for code and refactoring legacy code without tests.
The document provides an overview of basic C++ concepts including:
- C++ was developed as an extension of the C language and can be coded in an object-oriented or C-style.
- Keywords were added to support object-orientation, exceptions, and other features.
- Pointers in C++ store the address of a variable in memory.
- Blocks allow code sections to have their own local variables with minimized scope.
- Binding refers to converting functions/variables to machine addresses, which can be static/early or dynamic/late.
- Variables are statically scoped in C++ and type checking is done at compile-time rather than run-time.
- Most C++
GDG on Campus Monash hosted Info Session to provide details of the Solution Challenge to promote participation and hosted networking activities to help participants find their dream team
Testing Tools for Accessibility Enhancement Part II.pptxJulia Undeutsch
?
Automatic Testing Tools will help you get a first understanding of the accessibility of your website or web application. If you are new to accessibility, it will also help you learn more about the topic and the different issues that are occurring on the web when code is not properly written.
CIOs Speak Out - A Research Series by Jasper ColinJasper Colin
?
Discover key IT leadership insights from top CIOs on AI, cybersecurity, and cost optimization. Jasper Colin¡¯s research reveals what¡¯s shaping the future of enterprise technology. Stay ahead of the curve.
AuthZEN The OpenID Connect of Authorization - Gartner IAM EMEA 2025David Brossard
?
Today, the authorization world is fractured - each vendor supports its own APIs & protocols. But this is about to change: OpenID AuthZEN was created in late 2023 to establish much-needed modern authorization standards. As of late 2024, AuthZEN has a stable Implementers Draft, and is expected to reach Final Specification in 2025.
With AuthZEN, IAM teams can confidently externalize and standardize authorization across their application estate without being locked in to a proprietary API.
This session will describe the state of modern authorization, review the AuthZEN API, and demo our 15 interoperable implementations.
Getting the Best of TrueDEM ¨C April News & Updatespanagenda
?
Webinar Recording: https://www.panagenda.com/webinars/getting-the-best-of-truedem-april-news-updates/
Boost your Microsoft 365 experience with OfficeExpert TrueDEM! Join the April webinar for a deep dive into recent and upcoming features and functionalities of OfficeExpert TrueDEM. We¡¯ll showcase what¡¯s new and use practical application examples and real-life scenarios, to demonstrate how to leverage TrueDEM to optimize your M365 environment, troubleshoot issues, improve user satisfaction and productivity, and ultimately make data-driven business decisions.
These sessions will be led by our team of product management and consultants, who interact with customers daily and possess in-depth product knowledge, providing valuable insights and expert guidance.
What you¡¯ll take away
- Updates & info about the latest and upcoming features of TrueDEM
- Practical and realistic applications & examples for troubelshooting or improving your Microsoft Teams & M365 environment
- Use cases and examples of how our customers use TrueDEM
This presentation, delivered at Boston Code Camp 38, explores scalable multi-agent AI systems using Microsoft's AutoGen framework. It covers core concepts of AI agents, the building blocks of modern AI architectures, and how to orchestrate multi-agent collaboration using LLMs, tools, and human-in-the-loop workflows. Includes real-world use cases and implementation patterns.
Most people might think of a water faucet or even the tap on a keg of beer. But in the world of networking, "TAP" stands for "Traffic Access Point" or "Test Access Point." It's not a beverage or a sink fixture, but rather a crucial tool for network monitoring and testing. Khushi Communications is a top vendor in India, providing world-class Network TAP solutions. With their expertise, they help businesses monitor, analyze, and secure their networks efficiently.
Research Data Management (RDM): the management of dat in the research processHeilaPienaar
?
Presented as part of the M.IT degree at the Department of Information Science, University of Pretoria, South Africa. Module: Data management. 2023, 2024.
Sugarlab AI: How Much Does an XXX AI Porn Generator Cost in 2025Sugarlab AI
?
The cost of an XXX AI porn generator in 2025 varies depending on factors like AI sophistication, subscription plans, and additional expenses. Whether you're looking for a free AI porn video generator or a premium adult AI image generator, pricing ranges from basic tools to enterprise-level solutions. This article breaks down the costs, features, and what to expect from AI-driven adult content platforms.
Build Your Uber Clone App with Advanced FeaturesV3cube
?
Build your own ride-hailing business with our powerful Uber clone app, fully equipped with advanced features to give you a competitive edge. Start your own taxi business today!
More Information : https://www.v3cube.com/uber-clone/
En esta charla compartiremos la experiencia del equipo de Bitnami en la mejora de la seguridad de nuestros Helm Charts y Contenedores utilizando Kubescape como herramienta principal de validaci¨®n. Exploraremos el proceso completo, desde la identificaci¨®n de necesidades hasta la implementaci¨®n de validaciones automatizadas, incluyendo la creaci¨®n de herramientas para la comunidad.
Compartiremos nuestra experiencia en la implementaci¨®n de mejoras de seguridad en Charts y Contenedores, bas¨¢ndonos en las mejores pr¨¢cticas del mercado y utilizando Kubescape como herramienta de validaci¨®n. Explicaremos c¨®mo automatizamos estas validaciones integr¨¢ndolas en nuestro ciclo de vida de desarrollo, mejorando significativamente la seguridad de nuestros productos mientras manten¨ªamos la eficiencia operativa.
Durante la charla, los asistentes aprender¨¢n c¨®mo implementar m¨¢s de 60 validaciones de seguridad cr¨ªticas, incluyendo la configuraci¨®n segura de contenedores en modo no privilegiado, la aplicaci¨®n de buenas pr¨¢cticas en recursos de Kubernetes, y c¨®mo garantizar la compatibilidad con plataformas como OpenShift. Adem¨¢s, demostraremos una herramienta de self-assessment que desarrollamos para que cualquier usuario pueda evaluar y mejorar la seguridad de sus propios Charts bas¨¢ndose en esta experiencia.
Building High-Impact Teams Beyond the Product Triad.pdfRafael Burity
?
The product triad is broken.
Not because of flawed frameworks, but because it rarely works as it should in practice.
When it becomes a battle of roles, it collapses.
It only works with clarity, maturity, and shared responsibility.
How Telemedicine App Development is Revolutionizing Virtual Care.pptxDash Technologies Inc
?
Telemedicine app development builds software for remote doctor consultations and patient check-ups. These apps bridge healthcare professionals with patients via video calls, secure messages, and interactive interfaces. That helps practitioners to provide care without immediate face-to-face interactions; hence, simplifying access to medical care. Telemedicine applications also manage appointment scheduling, e-prescribing, and sending reminders.
Telemedicine apps do not only conduct remote consultations. They also integrate with entire healthcare platforms, such as patient forums, insurance claims processing, and providing medical information libraries. Remote patient monitoring enables providers to keep track of patients' vital signs. This helps them intervene and provide care whenever necessary. Telehealth app development eliminates geographical boundaries and facilitates easier communication.
In this blog, we will explore its market growth, essential features, and benefits for both patients and providers.
How Telemedicine App Development is Revolutionizing Virtual Care.pptxDash Technologies Inc
?
CSharp presentation and software developement
1. Notes on C#
BY: MATT BOGGUS
SOME MATERIAL BASED ON ROGER CRAWFIS¡¯ C#
SLIDES
2. C# and Java similarities
All classes are objects
? Compare System.Object to java.lang.Object
Similar compilation and runtime to Java
? Compare Java Virtual Machine to Common Language Runtime
Heap-based allocation
? Use ¡°new¡± keyword to instantiate
? Automatic garbage collection
3. C# language features
Namespaces
Classes
? Fields
? Properties
? Methods
? Events
Structs
Enums
Interfaces
? Methods
? Properties
? Events
Control Statements
? if, else, while, for, switch, foreach
5. Classes vs. structs
Both are user-defined types
Both can implement multiple interfaces
Both can contain
? Data
? Fields, constants, events, arrays
? Functions
? Methods, properties, indexers, operators, constructors
? Type definitions
? Classes, structs, enums, interfaces, delegates
6. Classes vs. structs
CLASS ; REFERENCE TYPE
Reference type
Original instance of the object
can be modified during
execution of method bodies
STRUCT ; VALUE TYPE
Value type
A copy of the object is made
and operated on inside method
bodies
Many types in XNA and MonoGame are defined as structs (ex: Vector2 and Rectangle)
Can pass structs as reference type using ¡®ref¡¯ keyword
8. Interfaces
An interface defines a contract
? An interface is a type
? Contain definitions for methods, properties, indexers,
and/or events
? Any class or struct implementing an interface must
support all parts of the contract
Interfaces provide no implementation
? When a class or struct implements an interface it must
provide the implementations
? SOLID: Depend upon abstractions not concretions
9. Interfaces
¡°Rigid¡± interface
? Functionality is explicitly defined
? Ex: OSU Component Library where interfaces include Javadoc comments
with methods¡¯ requires and ensures clauses (pre and post conditions)
¡°Flexible¡± interface
? Only method signatures are specified
? Ex:
IBird interface defines void Fly()
Duck class implements void Fly { position.y += 5; }
Penguin class implements void Fly { // no-op }
10. public interface IDelete {
void Delete();
}
public class TextBox : IDelete {
public void Delete() { ... }
}
public class ImageBox : IDelete {
public void Delete() { ... }
}
TextBox tb = new TextBox();
tb.Delete();
Interface example
IDelete deletableObj = new ImageBox();
deletableObj.Delete();
deletableObj = new TextBox();
deletableObj.Delete();
12. Abstract class
Similar to interfaces
? Cannot be instantiated
? In some cases, contain no executable code
? Can contain method headers/signatures and properties (more on
these in a bit), but unlike interfaces they can contain concrete
elements like method bodies and fields
Some quirks when working with abstract classes and interfaces
? A class that is derived from an abstract class may still implement
interfaces
? A concrete class may implement an unlimited number of interfaces,
but may inherit from only one abstract (or concrete) class
13. public abstract class Shape
{
protected int x = 50;
protected int y = 50;
public abstract int Area();
}
public class Square : Shape
{
public int width;
public int height;
public override int Area()
{
return width * height;
}
public void MoveLeft()
{
x--;
}
}
Abstract class example
Methods marked as abstract have no
bodies and must be overridden
Methods marked as virtual have
bodies and may be overridden
See http://msdn.microsoft.com/en-
us/library/sf985hc5.aspx for a longer
example
15. this
The this keyword is a predefined variable available in non-static function
members
? Used to access data and function members unambiguously
public class Person
{
private string name;
public Person(string name)
{
this.name = name;
}
public void Introduce(Person p)
{
if (p != this)
Console.WriteLine(¡°Hi, I¡¯m ¡° + name);
}
}
16. base
The base keyword can be used to access class members that are hidden
by similarly named members of the current class
public class Shape
{
private int x, y;
public override string ToString()
{
return "x=" + x + ",y=" + y;
}
}
public class Circle : Shape
{
private int r;
public override string ToString()
{
return base.ToString() + ",r=" + r;
}
}
17. Fields
A field or member variable holds data for a class or struct
Can hold:
? A built-in value type
? A class instance (a reference)
? A struct instance (actual data)
? An array of class or struct instances
(an array is actually a reference)
? An event
18. Field examples
static and instance
Output is:
20
2
30
2
public class NumStore
{
public static int i = 10;
public int j = 1;
public void AddAndPrint()
{
i=i+10;
j=j+1;
Console.WriteLine(i);
Console.WriteLine(j);
}
}
public class Exercise
{
static void Main()
{
NumStore x = new NumStore();
x.AddAndPrint();
NumStore y = new NumStore();
y.AddAndPrint();
Console.ReadKey();
}
}
19. Properties
Client side looks like a field
Internally behaves like method calls to get or set the field (i.e. more
abstract than a field)
Properties encapsulate a getting and setting a field
? Useful for changing the internal type for a field
? Useful for adding code or breakpoints when getting/setting a field
20. Properties ¨C syntax examples
type PropertyName { get; set; }
Many valid formats
int Score { get; set; }
string Name { get; }
double Time { get; private set; }
Code examples
? Person*.cs examples [Compare maintainability]
? http://www.dotnetperls.com/property
21. Modifiers
Public
? Accessible anywhere
Protected
? Accessible within its class and by derived class instances
Private
? Accessible only within the body of the class
? (Or anywhere if you use reflection)
Internal
? Intuitively, accessible only within this program (more specific definition here)
? The default, but you should generally pick public or private instead
22. Access modifier error example
Cannot have an interface that is less accessible than a concrete class that
implements it (also applies to base and inheriting classes)
interface GameObject // no access modifier, defaults to internal
{
void Draw();
void Update();
}
public class Monster : GameObject
{
// ... implementations of Draw() and Update() go here ...
}
24. Why C#?
Fits with
? .NET framework
? Large library of features and objects; portable and integrates with software written in
other languages
? Visual Studio
? Single point of access for software development, source code control, project
management, and code reviews
Additional reasons
? Game engines support C# -> XNA, Monogame, Unity
? Used in other CSE graphics courses (Game and Animation Techniques; Game
Capstone)
? More discussion of pros/cons of C# here
? More discussion of pros/cons of C# specific to game development here; this
subset of comments has some good insights
25. On your own
Java to C# resources
The C# Programming Language for Java Developers ¨C documentation of
language differences organized by programming constructs
Additional Suggestions from StackOverflow
26. public class Car : Vehicle
{
public enum Make { GM, Honda, BMW }
private Make make;
private string vid;
private Point location;
Car(Make make, string vid, Point loc)
{
this.make = make;
this.vid = vid;
this.location = loc;
}
public void Drive()
{ Console.WriteLine(¡°vroom¡±); }
}
Car c =
new Car(Car.Make.BMW,
¡°JF3559QT98¡±,
new Point(3,7));
c.Drive();
Class syntax example
27. How many methods should
classes/interfaces provide?
On your own references
Keep it simple!
? The Magical Number Seven, Plus or Minus Two
? The average person can hold 7 ¡À 2 objects in memory at a time
? Experts recall more by ¡°chunking¡± ¨C combining multiple objects
into one
? Think You're Multitasking? Think Again
? The average person is bad at multi-tasking, so focus on what you¡¯re
doing if you want it done well
29. Conversion operators
Can also specify user-defined explicit and implicit conversions
public class Note
{
private int value;
// Convert to hertz ¨C no loss of precision
public static implicit operator double(Note x) {
return ...;
}
// Convert to nearest note
public static explicit operator Note(double x) {
return ...;
}
}
Note n = (Note)442.578;
double d = n;
30. The is Operator
The is operator is used to dynamically test if the run-time type of an
object is compatible with a given type
private static void DoSomething(object o)
{
if (o is Car)
((Car)o).Drive();
}
31. The as Operator
The as operator tries to convert a variable to a specified type; if no such
conversion is possible the result is null
More efficient than using is operator
? Can test and convert in one operation
private static void DoSomething(object o)
{
Car c = o as Car;
if (c != null) c.Drive();
}