C - Aplicaciones de Consola - NameSpaces y BCL

4
Ing. Carlos Alberto Valdivia Salazar Página 1 APLICACIONES DE CONSOLA BCL Y LOS NAMESPACE A. Ejemplo de aplicación de NameSpaces personalizados 1. El NameSpace Cuentas y la estructura Cuenta (módulo modCuentas) Namespace Cuentas Module modCuenta Structure Cuenta Private Codigo As String Private Saldo As Double Private CodCliente As String End Structure End Module End Namespace 2. El NameSpace Cuentas y la estructura Lista (módulo modLista) Namespace Cuentas Module modLista Structure Lista Public Total As Integer Public Datos() As Cuenta End Structure End Module End Namespace 3. El NameSpace EspacioClientes y la estructura Cliente (módulo modCliente) Imports NewConsola5.Cuentas Namespace EspacioClientes Module modCliente Structure Cliente Dim Codigo As String Dim Nombres As String Dim C() As Cuenta

description

Consola con Visual Basic .NET

Transcript of C - Aplicaciones de Consola - NameSpaces y BCL

  • Ing. Carlos Alberto Valdivia Salazar Pgina 1

    APLICACIONES DE CONSOLA

    BCL Y LOS NAMESPACE

    A. Ejemplo de aplicacin de NameSpaces personalizados

    1. El NameSpace Cuentas y la estructura Cuenta (mdulo modCuentas)

    Namespace Cuentas

    Module modCuenta

    Structure Cuenta

    Private Codigo As String

    Private Saldo As Double

    Private CodCliente As String

    End Structure

    End Module

    End Namespace

    2. El NameSpace Cuentas y la estructura Lista (mdulo modLista)

    Namespace Cuentas

    Module modLista

    Structure Lista

    Public Total As Integer

    Public Datos() As Cuenta

    End Structure

    End Module

    End Namespace

    3. El NameSpace EspacioClientes y la estructura Cliente (mdulo modCliente)

    Imports NewConsola5.Cuentas

    Namespace EspacioClientes

    Module modCliente

    Structure Cliente

    Dim Codigo As String

    Dim Nombres As String

    Dim C() As Cuenta

  • Ing. Carlos Alberto Valdivia Salazar Pgina 2

    End Structure

    End Module

    End Namespace

    4. El Main utilizando las estructuras definidas (mdulo modPrincipal)

    Imports NewConsola5.Cuentas

    Imports NewConsola5.EspacioClientes

    Module modPrincipal

    Sub Main()

    Dim L As New Lista

    Dim C As New Cuenta

    Dim Cli As New Cliente

    End Sub

    End Module

    B. Utilizando los NameSpace de la BCL (System.Text)

    Imports System.Text

    Module Module1

    Sub Main()

    Dim Escuela As New StringBuilder

    Escuela.Append("Escuela profesional ")

    Escuela.Append("de Computacin ")

    Escuela.Append("e Informtica")

    Console.WriteLine(Escuela)

    Console.Read()

    End Sub

    End Module

  • Ing. Carlos Alberto Valdivia Salazar Pgina 3

    C. Manejo de cadenas (System.String)

    1. Recorriendo cada elemento de un String

    Sub Main()

    Dim strNombre As String

    strNombre = "Juan Perez"

    For Each C As Char In strNombre

    Console.Write(C & vbCrLf)

    If C = "P" Then

    Exit For

    End If

    Next

    Console.Read()

    End Sub

    2. Utilizando el mtodo Split

    Sub Main()

    Dim strCadena As String

    Dim Arreglo() As String

    strCadena = "Juan-Pedro-Maria-Ana"

    Arreglo = strCadena.Split(CChar("-"))

    For Each C As String In Arreglo

    Console.WriteLine(C)

    Next

    Console.Read()

    End Sub

  • Ing. Carlos Alberto Valdivia Salazar Pgina 4

    3. Utilizando System.DateTime

    Sub Main()

    Dim dtFecha As DateTime

    dtFecha = CDate("10/05/2010 02:35")

    dtFecha = dtFecha.AddDays(5)

    dtFecha = dtFecha.AddMonths(2)

    Console.WriteLine(dtFecha.ToString)

    Console.WriteLine(Date.Now)

    Console.WriteLine(dtFecha.Date)

    Console.WriteLine(dtFecha.Hour)

    Console.WriteLine(dtFecha.Minute)

    Console.WriteLine(dtFecha.DayOfWeek.ToString)

    Console.Read()

    End Sub