blogs

miércoles, 27 de mayo de 2015

Struct and Enum

Value typesEnums, Structs, primitive types

Reference type: Class

Structure versus Class

A structure  store its data, we can create objects of a struct similar to a class.For Example, it can have methods, field, properties,and support static methods. But a structure does not support static class, inheritance and this  can also not have default constructor while a class support inheritance, static class and default constructor.
When we create a struct, the  variable that we assigned include real data of the struct. If we assigned a new variable, this is a copy .The new  and original variable contain two independent copies, so when we modify a variable doesn't affect other.While a class is different if we modify a variable, this affects another because they both reference the same data.
  
Stack and heap
When we call the new operator on a class, it will be allocated on the heap while the structure  is created on the stack, because the structure is simple and light weight.

To create a class and a struct



To create unit test in order to test the different between  the struct and  class with Toggle breakpoints. 


To execute the class




To execute the struct


the result of struct is passed and the class is failed because the name of book  no have that be equals






Enum: The enum keyword is used to declare an enumeration, a distinct type that consists of set of named constants called the enumerator list.
It better define a enum directly within a namespace so that all classes in the namespace can access it .However, an enum can also be nested within a class or struct. By default, the first enumerator has the value 0













miércoles, 20 de mayo de 2015

Unity Test

Unit tests give developers and testers a quick way to look for logic errors in the methods of classes in Visual C#, Visual Basic, and Visual C++ projects. A unit test can be created one time and run every time that source code is changed to make sure that no bugs are introduced.
Additional test Attributes: Expand this section to show commented-out methods that can be used to include initialization and cleanup by using the following attributes:
a. [ClassInicialize()]: Use classInicialize to run code before we run the first test in the class.
b. [ClassCleanUp]: Use classCleanup to run code after all tests in a class have run.
c. [TestInitialize()]: Use TestInicialize to run code before we run each test.
d. [TestCleanUp()]: Use TestCleanUp to run code after each test has run.
e. [TestMethod]: This is the test.


For Example:















Concept about C#


Visual Studio: It is a tool that has multiple programming languages.For example C#,F#,etc.



We will use C#

  • C# support Object oriented programming.
  • Library base
  • This has a lot of type of application, e.g console
  • Unified execution: support all inside.


What is a Solution?
  • A solution can contain multiple languages.
  • A solution has a ".sln" extension 
  • The solution is represented by folders ".sh"
  • A solution contain projects
            A project has an ".csproj" extention
            The project organizes " .cs" files .





What is a namespace?

A namespace is a grouper, container or  collection logical of classes.


Using-> This brings context to that file, collections of classes contained in a namespace.



The object browser: This shows that has each library of the class or the project.
Object browser->namespace->class,structure, interface.


Creating a class library




We can attach references of other project or "ddl" file.





Example Class library don't have a main class, and library have "ddl" extension.

Execute project

Using debugging


 Execute:
start Debuggers
we will add  the following sentences :
            int number1 = 1;
            int number2 = 2;
            int sum = number1 + number2;
            Console.WriteLine("we are using a console project"+sum);
            Console.ReadLine();
In this example we want to result of two numbers and show using the console.







step over: Go to the next line
step into: Go to that line
step out: Not enter


Build or Build Solution: To Compile the Solution
Rebuild Solution: To remove the last files and generate others
Clean Solution:To delete any intermediate and output files.


We will create a class Student, we will use the class library.
  •  Rename the name the library. Right click on the  "Operation" project and change the name. We also change the name the namespace and the class.



A person has name, last name,age.