Click here to download Windows 7 Service Pack 1
Search This Blog
Monday, September 9, 2013
Windows 7 and Windows Server 2008 R2 Service Pack 1
Service Pack 1 for Windows Server 2008 R2 and Windows 7 provides ongoing improvements to the Windows operating system.
Click here to download Windows 7 Service Pack 1
Click here to download Windows 7 Service Pack 1
Etichete:
Windows
Thursday, July 18, 2013
Indexers C#
C# > Indexers
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
public partial class Form1 : Form
{
class Test
{
private string[] mStr = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "K"};
public int Length
{
get { return mStr.Length; }
}
// Indexer declaration.
public string this[int index]
{
get
{
return mStr[index];
}
set
{
mStr[index] = value;
}
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Test t = new Test();
// indexer set accessor
t[1] = "a";
t[2] = "b";
// indexer get accessor
for (int i = 0; i < t.Length -1 ; i++)
{
MessageBox.Show(t[i]);
}
}
}
}
Indexers enable to create a class that client applications can access as an array.
Implementation: encapsulate an internal collection or array.
Example:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{public partial class Form1 : Form
{
class Test
{
private string[] mStr = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "K"};
public int Length
{
get { return mStr.Length; }
}
// Indexer declaration.
public string this[int index]
{
get
{
return mStr[index];
}
set
{
mStr[index] = value;
}
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Test t = new Test();
// indexer set accessor
t[1] = "a";
t[2] = "b";
// indexer get accessor
for (int i = 0; i < t.Length -1 ; i++)
{
MessageBox.Show(t[i]);
}
}
}
}
Etichete:
c#
Asc Method Visual Basic
VB.NET > Functions > ASC
Asc Method returns an Integer value of character code corresponding to a character.
Example:
Dim IntCode As Integer
IntCode = Asc("A") '65
IntCode = Asc("a") '97
IntCode = Asc("@") '64
IntCode = Asc("?") '93
Asc Method returns an Integer value of character code corresponding to a character.
Example:
Dim IntCode As Integer
IntCode = Asc("A") '65
IntCode = Asc("a") '97
IntCode = Asc("@") '64
IntCode = Asc("?") '93
Etichete:
VB.NET
CType Function Visual Basic NET
VB.NET > Functions > CType
CType function returns the result of explicitly converting an expression to a specified data type.
Dim mStr As String = "100"
Dim mInt As Integer = CType(mStr, Integer) 'convert "100" string to mInt = 100 OK
mStr = "aaa"
mInt = CType(mStr, Integer) ' Error: Conversion from string "aaa" to type 'Integer' is not valid. NOK
End Sub
End Class
CType function returns the result of explicitly converting an expression to a specified data type.
Example:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.LoadPublic Class Form1
Dim mStr As String = "100"
Dim mInt As Integer = CType(mStr, Integer) 'convert "100" string to mInt = 100 OK
mStr = "aaa"
mInt = CType(mStr, Integer) ' Error: Conversion from string "aaa" to type 'Integer' is not valid. NOK
End Sub
End Class
Etichete:
VB.NET
Tuesday, July 16, 2013
Events C#
Events in C# are based on the delegate model.
To declare an event in a class the delegate type for the event must be declared.Events use the publisher-subscriber model.
A publisher is an object that contains the definition of the event and the delegate.
A subscriber is an object that accepts the event and provides an event handler.
Example:
using System;
using System.Collections.Generic;using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{public partial class Form1 : Form
{
public class Event
{
private int value;
public delegate void EventHandler(int v);
public event EventHandler ValueChanged;
protected virtual void OnValueChanged()
{
if (ValueChanged != null)
{
ValueChanged(value);
}
}
public Event()
{
}
public void SetValue(int n)
{
if (value != n)
{
value = n;
OnValueChanged(); // raise event
}
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Event ev = new Event();
ev.ValueChanged += ev_ValueChanged;
ev.SetValue(2);
ev.SetValue(3);
}
void ev_ValueChanged(int v)
{
MessageBox.Show("Event value : " + v.ToString());
}
}
}
Etichete:
c#
Logger class Delegate Example
C# > Delegate
Logger class Delegate Example
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
public partial class Form1 : Form
{
public class LoggerClass
{
public delegate void LogHandler(string message); // Declare a delegate
public void Log(LogHandler vLogHandler)
{
vLogHandler("Log begin");
// do stuff ...
vLogHandler("Log end");
}
}
static void Logger(string s)
{
MessageBox.Show(s);
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LoggerClass mClass = new LoggerClass();
LoggerClass.LogHandler mLogger = new LoggerClass.LogHandler(Logger); // create an instance of the delegate and pointing to the logging function.
mClass.Log(mLogger); // delegate will be passed to the Log() function.
}
}
}
Logger class Delegate Example
Example:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{public partial class Form1 : Form
{
public class LoggerClass
{
public delegate void LogHandler(string message); // Declare a delegate
public void Log(LogHandler vLogHandler)
{
vLogHandler("Log begin");
// do stuff ...
vLogHandler("Log end");
}
}
static void Logger(string s)
{
MessageBox.Show(s);
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LoggerClass mClass = new LoggerClass();
LoggerClass.LogHandler mLogger = new LoggerClass.LogHandler(Logger); // create an instance of the delegate and pointing to the logging function.
mClass.Log(mLogger); // delegate will be passed to the Log() function.
}
}
}
Etichete:
c#
Square brackets ([]) operator C#
C# > Operators > [] Operator
Square brackets ([]) operator is used for arrays, indexers, and attributes.
Examples
//arrays
int[] mList;
mList = new int[200];
//indexers
System.Collections.Hashtable h = new System.Collections.Hashtable();
h["e1"] = 1;
//attributes
[System.Serializable]
Square brackets ([]) operator is used for arrays, indexers, and attributes.
//arrays
int[] mList;
mList = new int[200];
//indexers
System.Collections.Hashtable h = new System.Collections.Hashtable();
h["e1"] = 1;
//attributes
[System.Serializable]
Etichete:
c#
Subscribe to:
Posts (Atom)