Here is a simple example of that:
string[] arString = null; arString = new string[2]; arString[0] = "First Element"; arString[1] = "Second Element"; foreach (string s1 in arString) { Console.WriteLine(s1); }
Visual Studio .NET Tips and Tricks, VB.NET Code Samples, C# Code Snippets, ASP.NET Code Samples, .NET Tips and Tricks, C# Tips & Tricks, Visual Studio 2010, .NET Framework Code Samples, VB.NET Tips & Tricks
string[] arString = null; arString = new string[2]; arString[0] = "First Element"; arString[1] = "Second Element"; foreach (string s1 in arString) { Console.WriteLine(s1); }
Private Sub WritePaddedText() ' Write a Padded Multiplication Table For i1 As Integer = 1 To 20 Console.WriteLine(i1.ToString.PadLeft(2) & " x 12 = " & (i1 * 12).ToString.PadLeft(3)) Next i1 End Sub
If Panel1.Height = 0 Then Panel1.Height = 110 Me.Height = Me.Height + 110 Else Panel1.Height = 0 Me.Height = Me.Height - 110 End If
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked System.Diagnostics.Process.Start("www.google.com") End Sub
Private Sub DateDiffExample() Dim dt1 As Date = New Date(2011, 5, 15, 10, 11, 2) Dim dt2 As Date = New Date(2011, 5, 15, 10, 12, 22) Dim dt3 As Long = DateDiff(DateInterval.Second, dt1, dt2) End Sub
Private Sub DateDiffExample() Dim dt1 As Date = New Date(2011, 5, 15, 10, 11, 2) Dim dt2 As Date = New Date(2011, 5, 15, 10, 12, 22) Dim dt3 As Long = DateDiff(DateInterval.Minute, dt1, dt2) End Sub
private void NoOfSpecificDaysThisMonth() { int iDayCnt = 4; // Defaults to four days DayOfWeek dw = DayOfWeek.Wednesday; DateTime firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); int iRemainder = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month) % 7; if ((dw >= firstDay.DayOfWeek) & ((dw - firstDay.DayOfWeek) < iRemainder)) { iDayCnt = iDayCnt+1; } else if ((dw < firstDay.DayOfWeek) & ((7+ dw - firstDay.DayOfWeek) < iRemainder)) { iDayCnt = iDayCnt + 1; } MessageBox.Show(iDayCnt.ToString()); }The above gives the No Of Wednesdays for the Current month. If you want for any specific month / year you can tweak it a bit like:
DateTime firstDay = new DateTime(2012, DateTime.Now.Month, 1); int iRemainder = DateTime.DaysInMonth(2012, DateTime.Now.Month) % 7;
private string ShirtSizes(int ShirtSize) { switch (ShirtSize) { case 36: return "Small"; case 38: return "Medium"; case 40: return "Large"; case 42: return "Extra Large"; case 44: return "XXL"; default: return "Free Size"; } }
switch (ShirtSize) { case 34: case 35: case 36: return "Small"; case 38: return "Medium"; ...
case 38: return "Medium"; break;
switch (sDayName.ToUpper () ) { case"1": MessageBox.Show("One"); case "2": MessageBox.Show("Two"); }
switch (sDayName.ToUpper () ) { case"1": MessageBox.Show("One"); break; case "2": MessageBox.Show("Two"); goto default; ...
private void ModFunctionCsharpExample() { int iRemainder = 31 % 3; MessageBox.Show("Remainder is " + iRemainder.ToString()); int iQuotient = Math.DivRem(31, 3, out iRemainder); MessageBox.Show("Remainder is " + iRemainder.ToString() + " and the Quotient is " + iQuotient); }
Private Sub frmWinSamAppMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown ' -- Sample Code for http://DotNetDud.BlogSpot.com Select Case e.KeyCode Case Keys.F1 MessageBox.Show("Help is on the way") Case Keys.F5 RefreshMethod() Case Keys.F9 MessageBox.Show("You have pressed F9") End Select End Sub
Public Class ClassDataBind Private sPrvName As String Private sOfferings As String Public Sub New(ByVal sName As String, ByVal sOffer As String) Me.Name = sName Me.Solutions = sOffer End Sub Property Name() As String Get Return sPrvName End Get Set(ByVal value As String) sPrvName = value End Set End Property
Private Sub FormDataBind_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load oDataBind = New ClassDataBind("Accenture", "Consulting") TextBox1.DataBindings.Add("Text", oDataBind, "Name", True, DataSourceUpdateMode.OnPropertyChanged) TextBox2.DataBindings.Add("Text", oDataBind, "Solutions", True, DataSourceUpdateMode.OnPropertyChanged) End Sub
Private Sub ButtonClicked(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = oDataBind.Name + " - " + oDataBind.Solutions End Sub