Archive for March, 2012

How to calculate your financial independence?

How much is necessary to join? How to calculate the magic number? It basically is a function of two variables: the level ofreal interest and personal expenses. The first is exogenous to the investor. He has no control. However, the second is a function of the chosen standard of living. It’s a personal decision.

If the investor is more conservative, wanting to consume only the income and not the principal equity needed to ensure financial independence is given by:

This way, the investor has an average monthly expenditure of $10,000 and the expected real interest rates are 3%, the equity necessary to ensure the independence will be $ 4 million (U.S. $ 10,000 x 12 / 0.03) . This equation is very sensitive to changes in interest rates. If they are 4%, the equity would be25% lower – $ 3 million. This shows the importance to seek more profitable investments.

This heritage should consider only the assets that generate some income. Not worth taking into account the property used as residence or vacation.

If you are having some difficult to understand the formula, ask for me, because the picture is in portuguese.


Create instance for what ?

Hello friends !

This time, we will talk about a subject that I have ever difficulty to learn, because I didn’t urderstand very well for what the instance is used.

Classes are declared by using the keyword class followed by the class name and a set of class members surrounded by curly braces. Everyclass has a constructor, which is called automatically any time an instance of a class is created. The purpose of constructors is to initialize classmembers when an instance of the class is created. Constructors do not have return values and always have the same name as the class. 


// Namespace Declaration
using System;

// helper class
class OutputClass
    string myString;

    // Constructor
    public OutputClass(string inputString)
myString = inputString;

    // Instance Method
    public void printString()
Console.WriteLine(“{0}”, myString);

    // Destructor
        // Some resource cleanup routines

// Program start class
class ExampleClass
    // Main begins program execution.
    public static void Main()
        // Instance of OutputClass
        OutputClass outCl = new OutputClass(“This is printed by the output class.”);

       // Call Output class’ method

In C#, there are two types of class members, instance and static. Instance class members belong to a specific occurrence of a class. Every time you declare an object of a certain class, you create a new instance of that class. The ExampleClass Main() method creates an instance of theOutputClass named outCl. You can create multiple instances of OutputClass with different names. Each of these instances are separate and stand alone. For example, if you create two OutputClass instances as follows:

    OutputClass oc1 = new OutputClass(“OutputClass1”);
OutputClass oc2 = 
new OutputClass(“OutputClass2”);

You create two separate instances of OutputClass with separate myString fields and separate printString() methods. On the other hand, if aclass member is static, you can access it simply by using the syntax <classname>.<static class member>. The instance names are oc1 and oc2.

Suppose OutputClass had the following static method:

    public static void staticPrinter()
Console.WriteLine(“There is only one of me.”);

Then you could call that function from Main() like this:


You must call static class members through their class name and not their instance name. This means that you don’t need to instantiate a class to use its static members. There is only ever one copy of a static class member. A good use of static members is when there is a function to be performed and no intermediate state is required, such as math calculations. Matter of fact, the .NET Frameworks Base Class Library includes a Math class that makes extensive use of static members.

Do you understand ? So, let’s practice !



Insert data in your DataBase

March 7, 2012 1 comment

Hello, after you have created your database and connected in it, you can input some data in the middle of the programming.

Like this example:

1: public class Program
2: {
3: static Person GetPerson()
4: {
5: Person person = new Person();
6: Console.WriteLine(“Name”);
7: person.Name = Console.ReadLine();
8: Console.WriteLine(“Email “);
9: person.Email = Console.ReadLine();
10: Console.WriteLine(“Gender (M ou F) “);
11: person.Gender= Convert.ToChar(Console.ReadLine());
12: Console.WriteLine(“Date of Born”);
13: person.DateofBorn= Convert.ToDateTime(Console.ReadLine());
14: return person;
15: }
17: static void Main(string[] args)
18: {
19: //
20: //calls a method that will fill out a object Person with users input
21: //
22: Person newPerson = GetPerson();
24: //
25: //string of connection that reports datas of DataBase that I will connect
26: //
27: string connectionString = @”Data Source=.\SQL;Initial Catalog=EstudyBlog;Integrated Security=True;Pooling=False”;
29: //
30: // Query TSQL with command that I will realize in DataBase
31: //
32: string query = “INSERT INTO Person (name, dateBorn, gender, email) values (@name, @dateBorn, @gender, @email)”;
34: SqlConnection conn = null;
35: try
36: {
37: //
38: //instance of connection
39: //
40: conn = new SqlConnection(connectionString);
42: //
43: //look for if the connection is close, if it is so it will open.
44: //
45: if (conn.State == ConnectionState.Closed)
46: {
47: //
48: //open connection
49: //
50: conn.Open();
51: }
53: //
54: // Creat of object command , that receives a query that will used in operation and the connection with tha DataBase.
55: //
56: SqlCommand cmd = new SqlCommand(query, conn);
58: //
59: // Add parameters in command
60: //
61: cmd.Parameters.Add(new SqlParameter(“name”, newPerson.Name));
62: cmd.Parameters.Add(new SqlParameter(“dateBorn”, newPerson.DateBorn));
63: cmd.Parameters.Add(new SqlParameter(“gender”, newPerson.Gender));
64: cmd.Parameters.Add(new SqlParameter(“email”, newPerson.Email));
66: //
67: // Execute command
68: //
69: cmd.ExecuteNonQuery();
71: //
72: // Close the connection with DataBase
73: //
74: conn.Close();
76: Console.WriteLine(“Person registered with success!!!”);
77: }
78: catch (Exception ex)
79: {
80: Console.WriteLine(ex.Message);
81: }
82: finally
83: {
84: //
85: // Ensures that the connection will be closed also that ocorres some error.
86: // Don’t exist problem in close a connection two times.
87: // The problem is in open a connection two times.
88: //
89: if (conn != null)
90: {
91: conn.Close();
92: }
93: }
94: }
95: }

Good studys for us !


%d bloggers like this: