简体   繁体   English

在C#中使用命名空间

[英]Using namespaces with C#

I'm just starting out learning C# this may be really simple but in VB i have these namespaces 我刚开始学习C#,这可能真的很简单,但是在VB中我有这些命名空间

<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Globalization" %>
<%@ import Namespace="System.Data.SqlClient" %>

How do I go about using those namespaces in C#? 如何在C#中使用这些名称空间?

I tried 我试过了

namespace System.Data

and

using System.Data

but they didn't work 但是他们没有用

Are you trying to import namespaces into an Asp.net page? 您是否正在尝试将名称空间导入Asp.net页面? If so the code you listed with a case change will work fine. 如果是这样,您列出的带有大小写更改的代码将可以正常工作。

<%@ Import Namespace="System.Data"%>

If you're trying to import them into an actual .cs file then you need the "using" directive 如果您尝试将它们导入到实际的.cs文件中,则需要“ using”指令

using System.Data;
using System.Globalization;
using System.Data;
using System.Data;
using System.Globalization;
using System.Data.SqlClient;

public class MyClass {}

These: 这些:

<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Globalization" %>
<%@ import Namespace="System.Data.SqlClient" %>

are ASP.NET page directives. 是ASP.NET页面指令。 They'll be the same whether your code-behind files are C# or VB. 无论您的代码隐藏文件是C#还是VB,它们都是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM