mac id -Media Access Control ID
you have to add reference of
Imports Microsoft.Win32
Imports System.Management
Imports System.IO
VB::
Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo As ManagementObject In moc
If (MACAddress = String.Empty) Then ' only return MAC Address from first card
If Convert.ToBoolean(mo("IPEnabled")) = True Then
MACAddress = mo("MacAddress").ToString()
mo.Dispose()
End If
End If
Next
MessageBox.Show(MACAddress)
C#:
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == String.Empty) // only return MAC Address from first card
{
if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
}
mo.Dispose();
}
MACAddress = MACAddress.Replace(":", "");
MessageBox.Show(MACAddress);
Sunday, October 18, 2009
Sunday, October 4, 2009
Difference between two dates in C#
public int GetTotalDays(DateTime startedDateTime)
{
//get the current date
DateTime nowDate = System.DateTime.Now;
//use timespan to get the number of days
System.TimeSpan span = nowDate - startedDateTime;
int days = (int)span.TotalDays;
return days;
}
{
//get the current date
DateTime nowDate = System.DateTime.Now;
//use timespan to get the number of days
System.TimeSpan span = nowDate - startedDateTime;
int days = (int)span.TotalDays;
return days;
}
Saturday, October 3, 2009
want to revere a string ??? solution is here c# ,VB
we can reverse a string in so many methods..
method 1
string str="Suresh Varma";
char[] rev=str.ToChatArray(str);
Array.Reverse(rev);
Response.Write(new string(rev));
out put...> amraV hseruS
method 2:
string str="9000588819";
string rev="";
for ( int i=0;i < str.length;i++)
{
rev+=str.SubString(str.length-i,1);
}
response.write(rev);
o/p 9188850009
method 3:(works only in VB.net)
Import Microsoft.VisualBasic
dim str as new string=strReverse("varma")
response.Write(str)
o/p amrav
method 1
string str="Suresh Varma";
char[] rev=str.ToChatArray(str);
Array.Reverse(rev);
Response.Write(new string(rev));
out put...> amraV hseruS
method 2:
string str="9000588819";
string rev="";
for ( int i=0;i < str.length;i++)
{
rev+=str.SubString(str.length-i,1);
}
response.write(rev);
o/p 9188850009
method 3:(works only in VB.net)
Import Microsoft.VisualBasic
dim str as new string=strReverse("varma")
response.Write(str)
o/p amrav
Subscribe to:
Comments (Atom)
