System Table Description
ALL_ARGUMENTS Arguments in object accessible to the user
ALL_CATALOG All tables, views, synonyms, sequences accessible to the user
ALL_COL_COMMENTS Comments on columns of accessible tables and views
ALL_CONSTRAINTS Constraint definitions on accessible tables
ALL_CONS_COLUMNS Information about accessible columns in constraint definitions
ALL_DB_LINKS Database links accessible to the user
ALL_ERRORS Current errors on stored objects that user is allowed to create
ALL_INDEXES Descriptions of indexes on tables accessible to the user
ALL_IND_COLUMNS COLUMNs comprising INDEXes on accessible TABLES
ALL_LOBS Description of LOBs contained in tables accessible to the user
ALL_OBJECTS Objects accessible to the user
ALL_OBJECT_TABLES Description of all object tables accessible to the user
ALL_SEQUENCES Description of SEQUENCEs accessible to the user
ALL_SNAPSHOTS Snapshots the user can access
ALL_SOURCE Current source on stored objects that user is allowed to create
ALL_SYNONYMS All synonyms accessible to the user
ALL_TABLES Description of relational tables accessible to the user
ALL_TAB_COLUMNS Columns of user's tables, views and clusters
ALL_TAB_COL_STATISTICS Columns of user's tables, views and clusters
ALL_TAB_COMMENTS Comments on tables and views accessible to the user
ALL_TRIGGERS Triggers accessible to the current user
ALL_TRIGGER_COLS Column usage in user's triggers or in triggers on user's tables
ALL_TYPES Description of types accessible to the user
ALL_UPDATABLE_COLUMNS Description of all updatable columns
ALL_USERS Information about all users of the database
ALL_VIEWS Description of views accessible to the user
DATABASE_COMPATIBLE_LEVEL Database compatible parameter set via init.ora
DBA_DB_LINKS All database links in the database
DBA_ERRORS Current errors on all stored objects in the database
DBA_OBJECTS All objects in the database
DBA_ROLES All Roles which exist in the database
DBA_ROLE_PRIVS Roles granted to users and roles
DBA_SOURCE Source of all stored objects in the database
DBA_TABLESPACES Description of all tablespaces
DBA_TAB_PRIVS All grants on objects in the database
DBA_TRIGGERS All triggers in the database
DBA_TS_QUOTAS Tablespace quotas for all users
DBA_USERS Information about all users of the database
DBA_VIEWS Description of all views in the database
DICTIONARY Description of data dictionary tables and views
DICT_COLUMNS Description of columns in data dictionary tables and views
GLOBAL_NAME global database name
NLS_DATABASE_PARAMETERS Permanent NLS parameters of the database
NLS_INSTANCE_PARAMETERS NLS parameters of the instance
NLS_SESSION_PARAMETERS NLS parameters of the user session
PRODUCT_COMPONENT_VERSION version and status information for component products
ROLE_TAB_PRIVS Table privileges granted to roles
SESSION_PRIVS Privileges which the user currently has set
SESSION_ROLES Roles which the user currently has enabled.
SYSTEM_PRIVILEGE_MAP Description table for privilege type codes. Maps privilege type numbers to type names
TABLE_PRIVILEGES Grants on objects for which the user is the grantor, grantee, owner, or an enabled role or PUBLIC is the grantee
TABLE_PRIVILEGE_MAP Description table for privilege (auditing option) type codes. Maps privilege (auditing option) type numbers to type names
Saturday, May 31, 2008
Sunday, May 11, 2008
Ajax example
<html><body><script type="text/javascript">function ajaxFunction(){
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4){
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.aspx",true);
xmlHttp.send(null);
}
</script>
<form name="myForm">
Name: <input type="text" onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form></body>
</html>Public Partial Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Expires = -1
Response.Clear()
Response.ClearContent()
Response.Write(System.DateTimeOffset.Now())
Response.End()
End Sub
End Class
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4){
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.aspx",true);
xmlHttp.send(null);
}
</script>
<form name="myForm">
Name: <input type="text" onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form></body>
</html>Public Partial Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Expires = -1
Response.Clear()
Response.ClearContent()
Response.Write(System.DateTimeOffset.Now())
Response.End()
End Sub
End Class
Thursday, May 8, 2008
Filling a dataset from a database
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ds = New DataSet()
'ds.ReadXml(Server.MapPath("cdCatalog.xml"))
connection = New Odbc.OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=D:\xslTest\XmlToDataSet\XmlToDataSet\bin\Debug\db1.mdb")
connection.Open()
Dim dataadapter As Odbc.OdbcDataAdapter = New Odbc.OdbcDataAdapter("select * from cd", connection)
dataadapter.Fill(ds, "table1")
Me.dg.DataSource = ds
Me.dg.DataMember = "table1"
Me.DataBind()
connection.Close()
ds = New DataSet()
'ds.ReadXml(Server.MapPath("cdCatalog.xml"))
connection = New Odbc.OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=D:\xslTest\XmlToDataSet\XmlToDataSet\bin\Debug\db1.mdb")
connection.Open()
Dim dataadapter As Odbc.OdbcDataAdapter = New Odbc.OdbcDataAdapter("select * from cd", connection)
dataadapter.Fill(ds, "table1")
Me.dg.DataSource = ds
Me.dg.DataMember = "table1"
Me.DataBind()
connection.Close()
Option Strict V's Option Explicit
Option Strict
restricts implicit data type conversions to only widening conversions. Widening conversions explicitly do not permit any data type conversions in which data loss may occur and any conversion between numeric types and strings. For more information about widening conversions, see the Widening Conversions section.
Option Explicit
means you have to declare all variables before you use them.
restricts implicit data type conversions to only widening conversions. Widening conversions explicitly do not permit any data type conversions in which data loss may occur and any conversion between numeric types and strings. For more information about widening conversions, see the Widening Conversions section.
Option Explicit
means you have to declare all variables before you use them.
DatagridView populated from dataset extracted from xml.
Public Class Form1
Private Sub ShowData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowData.Click
Dim ds As DataSet = New DataSet()
ds.ReadXml("D:\xslTest\XmlToDataSet\XmlToDataSet\cdCatalog.xml")
Me.dgv.DataSource = ds
Me.dgv.DataMember = "cd"
End Sub
End Class
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="CdCatalog.xsl"?>
<catalog>
<cd>
<title>
Empire Burlesque</title>
<artist>
Bob Dylan</artist>
<country>
USA</country>
<company>
Columbia</company>
<price>
10.90</price>
<year>
1985</year>
</cd>
<cd>
<title>
Hide your heart</title>
<artist>
Bonnie Tyler</artist>
<country>
UK</country>
<company>
CBS Records</company>
<price>
9.90</price>
<year>
1988</year>
</cd>
<cd>
<title>
Greatest Hits</title>
<artist>
Dolly Parton</artist>
<country>
USA</country>
<company>
RCA</company>
<price>
9.90</price>
<year>
1982</year>
</cd>
<cd>
<title>
Still got the blues</title>
<artist>
Gary Moore</artist>
<country>
UK</country>
<company>
Virgin records</company>
<price>
10.20</price>
<year>
1990</year>
</cd>
<cd>
<title>
Eros</title>
<artist>
Eros Ramazzotti</artist>
<country>
EU</country>
<company>
BMG</company>
<price>
9.90</price>
<year>
1997</year>
</cd>
<cd>
<title>
One night only</title>
<artist>
Bee Gees</artist>
<country>
UK</country>
<company>
Polydor</company>
<price>
10.90</price>
<year>
1998</year>
</cd>
<cd>
<title>
Sylvias Mother</title>
<artist>
Dr.Hook</artist>
<country>
UK</country>
<company>
CBS</company>
<price>
8.10</price>
<year>
1973</year>
</cd>
<cd>
<title>
Maggie May</title>
<artist>
Rod Stewart</artist>
<country>
UK</country>
<company>
Pickwick</company>
<price>
8.50</price>
<year>
1990</year>
</cd>
<cd>
<title>
Romanza</title>
<artist>
Andrea Bocelli</artist>
<country>
EU</country>
<company>
Polydor</company>
<price>
10.80</price>
<year>
1996</year>
</cd>
<cd>
<title>
When a man loves a woman</title>
<artist>
Percy Sledge</artist>
<country>
USA</country>
<company>
Atlantic</company>
<price>
8.70</price>
<year>
1987</year>
</cd>
<cd>
<title>
Black angel</title>
<artist>
Savage Rose</artist>
<country>
EU</country>
<company>
Mega</company>
<price>
10.90</price>
<year>
1995</year>
</cd>
<cd>
<title>
1999 Grammy Nominees</title>
<artist>
Many</artist>
<country>
USA</country>
<company>
Grammy</company>
<price>
10.20</price>
<year>
1999</year>
</cd>
<cd>
<title>
For the good times</title>
<artist>
Kenny Rogers</artist>
<country>
UK</country>
<company>
Mucik Master</company>
<price>
8.70</price>
<year>
1995</year>
</cd>
<cd>
<title>
Big Willie style</title>
<artist>
Will Smith</artist>
<country>
USA</country>
<company>
Columbia</company>
<price>
9.90</price>
<year>
1997</year>
</cd>
<cd>
<title>
Tupelo Honey</title>
<artist>
Van Morrison</artist>
<country>
UK</country>
<company>
Polydor</company>
<price>
8.20</price>
<year>
1971</year>
</cd>
<cd>
<title>
Soulsville</title>
<artist>
Jorn Hoel</artist>
<country>
Norway</country>
<company>
WEA</company>
<price>
7.90</price>
<year>
1996</year>
</cd>
<cd>
<title>
The very best of</title>
<artist>
Cat Stevens</artist>
<country>
UK</country>
<company>
Island</company>
<price>
8.90</price>
<year>
1990</year>
</cd>
<cd>
<title>
Stop</title>
<artist>
Sam Brown</artist>
<country>
UK</country>
<company>
A and M</company>
<price>
8.90</price>
<year>
1988</year>
</cd>
<cd>
<title>
Bridge of Spies</title>
<artist>
T`Pau</artist>
<country>
UK</country>
<company>
Siren</company>
<price>
7.90</price>
<year>
1987</year>
</cd>
<cd>
<title>
Private Dancer</title>
<artist>
Tina Turner</artist>
<country>
UK</country>
<company>
Capitol</company>
<price>
8.90</price>
<year>
1983</year>
</cd>
<cd>
<title>
Midt om natten</title>
<artist>
Kim Larsen</artist>
<country>
EU</country>
<company>
Medley</company>
<price>
7.80</price>
<year>
1983</year>
</cd>
<cd>
<title>
Pavarotti Gala Concert</title>
<artist>
Luciano Pavarotti</artist>
<country>
UK</country>
<company>
DECCA</company>
<price>
9.90</price>
<year>
1991</year>
</cd>
<cd>
<title>
The dock of the bay</title>
<artist>
Otis Redding</artist>
<country>
USA</country>
<company>
Atlantic</company>
<price>
7.90</price>
<year>
1987</year>
</cd>
<cd>
<title>
Picture book</title>
<artist>
Simply Red</artist>
<country>
EU</country>
<company>
Elektra</company>
<price>
7.20</price>
<year>
1985</year>
</cd>
<cd>
<title>
Red</title>
<artist>
The Communards</artist>
<country>
UK</country>
<company>
London</company>
<price>
7.80</price>
<year>
1987</year>
</cd>
<cd>
<title>
Unchain my heart</title>
<artist>
Joe Cocker</artist>
<country>
USA</country>
<company>
EMI</company>
<price>
8.20</price>
<year>
1987</year>
</cd>
</catalog>
Empire Burlesque Bob Dylan USA Columbia 10.90 1985
Hide your heart Bonnie Tyler UK CBS Records 9.90 1988
Greatest Hits Dolly Parton USA RCA 9.90 1982
Still got the blues Gary Moore UK Virgin records 10.20 1990
Eros Eros Ramazzotti EU BMG 9.90 1997
One night only Bee Gees UK Polydor 10.90 1998
Sylvias Mother Dr.Hook UK CBS 8.10 1973
Maggie May Rod Stewart UK Pickwick 8.50 1990
Romanza Andrea Bocelli EU Polydor 10.80 1996
When a man loves a woman Percy Sledge USA Atlantic 8.70 1987
Black angel Savage Rose EU Mega 10.90 1995
1999 Grammy Nominees Many USA Grammy 10.20 1999
For the good times Kenny Rogers UK Mucik Master 8.70 1995
Big Willie style Will Smith USA Columbia 9.90 1997
Tupelo Honey Van Morrison UK Polydor 8.20 1971
Soulsville Jorn Hoel Norway WEA 7.90 1996
The very best of Cat Stevens UK Island 8.90 1990
Stop Sam Brown UK A and M 8.90 1988
Bridge of Spies T`Pau UK Siren 7.90 1987
Private Dancer Tina Turner UK Capitol 8.90 1983
Midt om natten Kim Larsen EU Medley 7.80 1983
Pavarotti Gala Concert Luciano Pavarotti UK DECCA 9.90 1991
The dock of the bay Otis Redding USA Atlantic 7.90 1987
Picture book Simply Red EU Elektra 7.20 1985
Red The Communards UK London 7.80 1987
Unchain my heart Joe Cocker USA EMI 8.20 1987
Private Sub ShowData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowData.Click
Dim ds As DataSet = New DataSet()
ds.ReadXml("D:\xslTest\XmlToDataSet\XmlToDataSet\cdCatalog.xml")
Me.dgv.DataSource = ds
Me.dgv.DataMember = "cd"
End Sub
End Class
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="CdCatalog.xsl"?>
<catalog>
<cd>
<title>
Empire Burlesque</title>
<artist>
Bob Dylan</artist>
<country>
USA</country>
<company>
Columbia</company>
<price>
10.90</price>
<year>
1985</year>
</cd>
<cd>
<title>
Hide your heart</title>
<artist>
Bonnie Tyler</artist>
<country>
UK</country>
<company>
CBS Records</company>
<price>
9.90</price>
<year>
1988</year>
</cd>
<cd>
<title>
Greatest Hits</title>
<artist>
Dolly Parton</artist>
<country>
USA</country>
<company>
RCA</company>
<price>
9.90</price>
<year>
1982</year>
</cd>
<cd>
<title>
Still got the blues</title>
<artist>
Gary Moore</artist>
<country>
UK</country>
<company>
Virgin records</company>
<price>
10.20</price>
<year>
1990</year>
</cd>
<cd>
<title>
Eros</title>
<artist>
Eros Ramazzotti</artist>
<country>
EU</country>
<company>
BMG</company>
<price>
9.90</price>
<year>
1997</year>
</cd>
<cd>
<title>
One night only</title>
<artist>
Bee Gees</artist>
<country>
UK</country>
<company>
Polydor</company>
<price>
10.90</price>
<year>
1998</year>
</cd>
<cd>
<title>
Sylvias Mother</title>
<artist>
Dr.Hook</artist>
<country>
UK</country>
<company>
CBS</company>
<price>
8.10</price>
<year>
1973</year>
</cd>
<cd>
<title>
Maggie May</title>
<artist>
Rod Stewart</artist>
<country>
UK</country>
<company>
Pickwick</company>
<price>
8.50</price>
<year>
1990</year>
</cd>
<cd>
<title>
Romanza</title>
<artist>
Andrea Bocelli</artist>
<country>
EU</country>
<company>
Polydor</company>
<price>
10.80</price>
<year>
1996</year>
</cd>
<cd>
<title>
When a man loves a woman</title>
<artist>
Percy Sledge</artist>
<country>
USA</country>
<company>
Atlantic</company>
<price>
8.70</price>
<year>
1987</year>
</cd>
<cd>
<title>
Black angel</title>
<artist>
Savage Rose</artist>
<country>
EU</country>
<company>
Mega</company>
<price>
10.90</price>
<year>
1995</year>
</cd>
<cd>
<title>
1999 Grammy Nominees</title>
<artist>
Many</artist>
<country>
USA</country>
<company>
Grammy</company>
<price>
10.20</price>
<year>
1999</year>
</cd>
<cd>
<title>
For the good times</title>
<artist>
Kenny Rogers</artist>
<country>
UK</country>
<company>
Mucik Master</company>
<price>
8.70</price>
<year>
1995</year>
</cd>
<cd>
<title>
Big Willie style</title>
<artist>
Will Smith</artist>
<country>
USA</country>
<company>
Columbia</company>
<price>
9.90</price>
<year>
1997</year>
</cd>
<cd>
<title>
Tupelo Honey</title>
<artist>
Van Morrison</artist>
<country>
UK</country>
<company>
Polydor</company>
<price>
8.20</price>
<year>
1971</year>
</cd>
<cd>
<title>
Soulsville</title>
<artist>
Jorn Hoel</artist>
<country>
Norway</country>
<company>
WEA</company>
<price>
7.90</price>
<year>
1996</year>
</cd>
<cd>
<title>
The very best of</title>
<artist>
Cat Stevens</artist>
<country>
UK</country>
<company>
Island</company>
<price>
8.90</price>
<year>
1990</year>
</cd>
<cd>
<title>
Stop</title>
<artist>
Sam Brown</artist>
<country>
UK</country>
<company>
A and M</company>
<price>
8.90</price>
<year>
1988</year>
</cd>
<cd>
<title>
Bridge of Spies</title>
<artist>
T`Pau</artist>
<country>
UK</country>
<company>
Siren</company>
<price>
7.90</price>
<year>
1987</year>
</cd>
<cd>
<title>
Private Dancer</title>
<artist>
Tina Turner</artist>
<country>
UK</country>
<company>
Capitol</company>
<price>
8.90</price>
<year>
1983</year>
</cd>
<cd>
<title>
Midt om natten</title>
<artist>
Kim Larsen</artist>
<country>
EU</country>
<company>
Medley</company>
<price>
7.80</price>
<year>
1983</year>
</cd>
<cd>
<title>
Pavarotti Gala Concert</title>
<artist>
Luciano Pavarotti</artist>
<country>
UK</country>
<company>
DECCA</company>
<price>
9.90</price>
<year>
1991</year>
</cd>
<cd>
<title>
The dock of the bay</title>
<artist>
Otis Redding</artist>
<country>
USA</country>
<company>
Atlantic</company>
<price>
7.90</price>
<year>
1987</year>
</cd>
<cd>
<title>
Picture book</title>
<artist>
Simply Red</artist>
<country>
EU</country>
<company>
Elektra</company>
<price>
7.20</price>
<year>
1985</year>
</cd>
<cd>
<title>
Red</title>
<artist>
The Communards</artist>
<country>
UK</country>
<company>
London</company>
<price>
7.80</price>
<year>
1987</year>
</cd>
<cd>
<title>
Unchain my heart</title>
<artist>
Joe Cocker</artist>
<country>
USA</country>
<company>
EMI</company>
<price>
8.20</price>
<year>
1987</year>
</cd>
</catalog>
Empire Burlesque Bob Dylan USA Columbia 10.90 1985
Hide your heart Bonnie Tyler UK CBS Records 9.90 1988
Greatest Hits Dolly Parton USA RCA 9.90 1982
Still got the blues Gary Moore UK Virgin records 10.20 1990
Eros Eros Ramazzotti EU BMG 9.90 1997
One night only Bee Gees UK Polydor 10.90 1998
Sylvias Mother Dr.Hook UK CBS 8.10 1973
Maggie May Rod Stewart UK Pickwick 8.50 1990
Romanza Andrea Bocelli EU Polydor 10.80 1996
When a man loves a woman Percy Sledge USA Atlantic 8.70 1987
Black angel Savage Rose EU Mega 10.90 1995
1999 Grammy Nominees Many USA Grammy 10.20 1999
For the good times Kenny Rogers UK Mucik Master 8.70 1995
Big Willie style Will Smith USA Columbia 9.90 1997
Tupelo Honey Van Morrison UK Polydor 8.20 1971
Soulsville Jorn Hoel Norway WEA 7.90 1996
The very best of Cat Stevens UK Island 8.90 1990
Stop Sam Brown UK A and M 8.90 1988
Bridge of Spies T`Pau UK Siren 7.90 1987
Private Dancer Tina Turner UK Capitol 8.90 1983
Midt om natten Kim Larsen EU Medley 7.80 1983
Pavarotti Gala Concert Luciano Pavarotti UK DECCA 9.90 1991
The dock of the bay Otis Redding USA Atlantic 7.90 1987
Picture book Simply Red EU Elektra 7.20 1985
Red The Communards UK London 7.80 1987
Unchain my heart Joe Cocker USA EMI 8.20 1987
Wednesday, May 7, 2008
Inheritance in vb and c# examples
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
public interface IPerson
{
String MyToString();
}
public class Person:IPerson
{
private String personName = "";
public Person(String name)
{
personName = name;
}
public virtual String MyToString()
{
String output = "";
output += base.ToString()+ " " + personName;
return output;
}
}
public class Worker:Person, IPerson
{
private int workerPay = 0;
public Worker(int pay, String name)
: base(name)
{
workerPay = pay;
}
public override string MyToString()
{
return base.MyToString() + " The worker gets paid " + workerPay;
}
}
public abstract class DomesticHelp:Person
{
private String type = "";
public DomesticHelp(String name, String type ):base(name)
{
this.type = type;
}
public override string MyToString()
{
return base.MyToString() + " The domestic help is of type " + type;
}
}
public class Butler:DomesticHelp
{
public Butler(String name)
: base(name, "butler")
{
}
}
public class Horse
{
public string MyToString()
{
return "I'm a horse not a person";
}
}
public class Program
{
static void Main(string[] args)
{
Person p = new Person ("noel");
Console.WriteLine(p.MyToString());
Worker w = new Worker(2098, "John");
p = new Worker(2345, "nerk");
IPerson x = new Worker(2345, "Fred");
Console.WriteLine(p.MyToString());
Console.WriteLine(w.MyToString());
Console.WriteLine(x.MyToString());
Horse h = new Horse();
Console.WriteLine(h.MyToString());
//the next line will not compile
//h = new Worker(2345, "Fred");
Person p2 = new Person("noel2");
Console.WriteLine(p2.MyToString());
Worker w2 = new Worker(2098, "John2");
Console.WriteLine(w2.MyToString());
p2 = w2;
Console.WriteLine(p2.MyToString());
Console.WriteLine(w2.MyToString());
DomesticHelp d = new Butler("Jeeves");
Console.WriteLine(d.MyToString());
//Person p3 = new Person("noel3");
//Console.WriteLine(p3.MyToString());
//Worker w3 = new Worker(2098, "John3");
//Console.WriteLine(w3.MyToString());
//will not compile w3 = p3;
//will compile but a person cannot be cast to a worker as
//the person does not have space for a pay variable w3 = (Worker)p3;
//Console.WriteLine(p3.MyToString());
//Console.WriteLine(w3.MyToString());
//Console.ReadKey();
}
}
}
Output =
ConsoleApplication1.Person noel
ConsoleApplication1.Worker nerk The worker gets paid 2345
ConsoleApplication1.Worker John The worker gets paid 2098
ConsoleApplication1.Worker Fred The worker gets paid 2345
I'm a horse not a person
ConsoleApplication1.Person noel2
ConsoleApplication1.Worker John2 The worker gets paid 2098
ConsoleApplication1.Worker John2 The worker gets paid 2098
ConsoleApplication1.Worker John2 The worker gets paid 2098
ConsoleApplication1.Butler Jeeves The domestic help is of type butler
Example as vb
Imports System
Imports System.Collections.Generic
Imports System.Text
Namespace ConsoleApplication3
Public Interface IPerson
Function MyToString() As String
End Interface
Public Class Person
Implements IPerson
Private personName As String = ""
Public Sub New(ByVal name As String)
personName = name
End Sub
Public Overridable Function MyToString() As String Implements IPerson.MyToString
Dim output As String = ""
output &= MyBase.ToString() & " " & personName
Return output
End Function
End Class
Public Class Worker
Inherits Person
Implements IPerson
Private workerPay As Integer = 0
Public Sub New(ByVal pay As Integer, ByVal name As String)
MyBase.New(name)
workerPay = pay
End Sub
Public Overrides Function MyToString() As String
Return MyBase.MyToString() & " The worker gets paid " & workerPay
End Function
End Class
Public MustInherit Class DomesticHelp
Inherits Person
Private type As String = ""
Public Sub New(ByVal name As String, ByVal type As String)
MyBase.New(name)
Me.type = type
End Sub
Public Overrides Function MyToString() As String
Return MyBase.MyToString() & " The domestic help is of type " & type
End Function
End Class
Public Class Butler
Inherits DomesticHelp
Public Sub New(ByVal name As String)
MyBase.new(name, "butler")
End Sub
End Class
Public Class Horse
Public Function MyToString() As String
Return "I'm a horse not a person"
End Function
End Class
Public Class Program
Shared Sub Main(ByVal args() As String)
Dim p As Person = New Person("noel")
Console.WriteLine(p.MyToString())
Dim w As Worker = New Worker(2098, "John")
p = New Worker(2345, "nerk")
Dim x As IPerson = New Worker(2345, "Fred")
Console.WriteLine(p.MyToString())
Console.WriteLine(w.MyToString())
Console.WriteLine(x.MyToString())
Dim h As Horse = New Horse()
Console.WriteLine(h.MyToString())
'the next line will not compile
'h = new Worker(2345, "Fred");
Dim p2 As Person = New Person("noel2")
Console.WriteLine(p2.MyToString())
Dim w2 As Worker = New Worker(2098, "John2")
Console.WriteLine(w2.MyToString())
p2 = w2
Console.WriteLine(p2.MyToString())
Console.WriteLine(w2.MyToString())
Dim d As DomesticHelp = New Butler("Jeeves")
Console.WriteLine(d.MyToString())
Console.ReadKey()
End Sub
End Class
End Namespace
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
public interface IPerson
{
String MyToString();
}
public class Person:IPerson
{
private String personName = "";
public Person(String name)
{
personName = name;
}
public virtual String MyToString()
{
String output = "";
output += base.ToString()+ " " + personName;
return output;
}
}
public class Worker:Person, IPerson
{
private int workerPay = 0;
public Worker(int pay, String name)
: base(name)
{
workerPay = pay;
}
public override string MyToString()
{
return base.MyToString() + " The worker gets paid " + workerPay;
}
}
public abstract class DomesticHelp:Person
{
private String type = "";
public DomesticHelp(String name, String type ):base(name)
{
this.type = type;
}
public override string MyToString()
{
return base.MyToString() + " The domestic help is of type " + type;
}
}
public class Butler:DomesticHelp
{
public Butler(String name)
: base(name, "butler")
{
}
}
public class Horse
{
public string MyToString()
{
return "I'm a horse not a person";
}
}
public class Program
{
static void Main(string[] args)
{
Person p = new Person ("noel");
Console.WriteLine(p.MyToString());
Worker w = new Worker(2098, "John");
p = new Worker(2345, "nerk");
IPerson x = new Worker(2345, "Fred");
Console.WriteLine(p.MyToString());
Console.WriteLine(w.MyToString());
Console.WriteLine(x.MyToString());
Horse h = new Horse();
Console.WriteLine(h.MyToString());
//the next line will not compile
//h = new Worker(2345, "Fred");
Person p2 = new Person("noel2");
Console.WriteLine(p2.MyToString());
Worker w2 = new Worker(2098, "John2");
Console.WriteLine(w2.MyToString());
p2 = w2;
Console.WriteLine(p2.MyToString());
Console.WriteLine(w2.MyToString());
DomesticHelp d = new Butler("Jeeves");
Console.WriteLine(d.MyToString());
//Person p3 = new Person("noel3");
//Console.WriteLine(p3.MyToString());
//Worker w3 = new Worker(2098, "John3");
//Console.WriteLine(w3.MyToString());
//will not compile w3 = p3;
//will compile but a person cannot be cast to a worker as
//the person does not have space for a pay variable w3 = (Worker)p3;
//Console.WriteLine(p3.MyToString());
//Console.WriteLine(w3.MyToString());
//Console.ReadKey();
}
}
}
Output =
ConsoleApplication1.Person noel
ConsoleApplication1.Worker nerk The worker gets paid 2345
ConsoleApplication1.Worker John The worker gets paid 2098
ConsoleApplication1.Worker Fred The worker gets paid 2345
I'm a horse not a person
ConsoleApplication1.Person noel2
ConsoleApplication1.Worker John2 The worker gets paid 2098
ConsoleApplication1.Worker John2 The worker gets paid 2098
ConsoleApplication1.Worker John2 The worker gets paid 2098
ConsoleApplication1.Butler Jeeves The domestic help is of type butler
Example as vb
Imports System
Imports System.Collections.Generic
Imports System.Text
Namespace ConsoleApplication3
Public Interface IPerson
Function MyToString() As String
End Interface
Public Class Person
Implements IPerson
Private personName As String = ""
Public Sub New(ByVal name As String)
personName = name
End Sub
Public Overridable Function MyToString() As String Implements IPerson.MyToString
Dim output As String = ""
output &= MyBase.ToString() & " " & personName
Return output
End Function
End Class
Public Class Worker
Inherits Person
Implements IPerson
Private workerPay As Integer = 0
Public Sub New(ByVal pay As Integer, ByVal name As String)
MyBase.New(name)
workerPay = pay
End Sub
Public Overrides Function MyToString() As String
Return MyBase.MyToString() & " The worker gets paid " & workerPay
End Function
End Class
Public MustInherit Class DomesticHelp
Inherits Person
Private type As String = ""
Public Sub New(ByVal name As String, ByVal type As String)
MyBase.New(name)
Me.type = type
End Sub
Public Overrides Function MyToString() As String
Return MyBase.MyToString() & " The domestic help is of type " & type
End Function
End Class
Public Class Butler
Inherits DomesticHelp
Public Sub New(ByVal name As String)
MyBase.new(name, "butler")
End Sub
End Class
Public Class Horse
Public Function MyToString() As String
Return "I'm a horse not a person"
End Function
End Class
Public Class Program
Shared Sub Main(ByVal args() As String)
Dim p As Person = New Person("noel")
Console.WriteLine(p.MyToString())
Dim w As Worker = New Worker(2098, "John")
p = New Worker(2345, "nerk")
Dim x As IPerson = New Worker(2345, "Fred")
Console.WriteLine(p.MyToString())
Console.WriteLine(w.MyToString())
Console.WriteLine(x.MyToString())
Dim h As Horse = New Horse()
Console.WriteLine(h.MyToString())
'the next line will not compile
'h = new Worker(2345, "Fred");
Dim p2 As Person = New Person("noel2")
Console.WriteLine(p2.MyToString())
Dim w2 As Worker = New Worker(2098, "John2")
Console.WriteLine(w2.MyToString())
p2 = w2
Console.WriteLine(p2.MyToString())
Console.WriteLine(w2.MyToString())
Dim d As DomesticHelp = New Butler("Jeeves")
Console.WriteLine(d.MyToString())
Console.ReadKey()
End Sub
End Class
End Namespace
Subscribe to:
Comments (Atom)