Reputation: 2925
'm a newbie in C# normally my forte is C++ and VB. I have 2 problem in which i have commented on the code:
1.) Blue squiggle lines appear on the 3 Uses it say ""A using namespace directive can only be applied to namespaces; 'System.Object' ... "
2.) i could not get an output IP address from my variable LocalIP in which i declared as public.
Thanks in advance.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
//Blue squiggly line appear on this 2 Uses
using Dns = System.Net.Dns;
using AddressFamily = System.Net.Sockets.AddressFamily;
namespace WindowsFormsApplication1
{
public partial class frm_Log : Form
{
public String localIP;
public string LocalIPAddress()
{
IPHostEntry host;
//string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
break;
}
}
return localIP;
}
....
....
// variable localIP.Trim() does not giveout any output
MyValue="LogAccept,"+this.txt_UserName.Text.Trim()+","+this.txt_Password.Text.Trim() + "," + localIP.Trim() ;
....
....
Upvotes: 0
Views: 1809
Reputation: 2925
Original Code was
using System
....
using System.Object;
using System.Net.Dns;
using System.Net.Sockets.AddressFamily;
....
resolution
//using System.Object --> since uses system already defined.
using Dns = System.Net.Dns;
using AddressFamily = System.Net.Sockets.AddressFamily;
Upvotes: 0
Reputation: 21773
http://msdn.microsoft.com/en-US/library/sf0df423(v=vs.80).aspx suggests this syntax:
using Dns = System.Net.Dns;
The standard version of using (using System.Linq;
) can only target namespaces, not classes in a namespace. If you have imported a whole namespace, though, you don't need to specifically import anything in it.
Upvotes: 1
Reputation: 34846
System.Object
is a class. System
is the namespace, which you already have defined as the first using
at the top of the file.
Upvotes: 1