I'm using the library, SoundTouchSharp, in my project. How do I create an instance of it? I don't really understand if I need to use the "using" line and if I need anything else so that I can eventually get
SoundTouchSharp s = new SoundTouchSharp();
because right now the compiler says:
"the type or namespace name SoundTouchSharp could not be found."
I included SoundTouchSharp as a reference (after creating a .dll version of the .cs file), and I also put both SoundTouchSharp.dll and soundtouch.dll in the bin/Debug folder.
So now what?
I included SoundTouchSharp as a reference (after creating a .dll
version of the .cs file), and I also put both SoundTouchSharp.dll and
soundtouch.dll in the bin/Debug folder.
If you want to use the SoundTouchSharp class from the BigMansStuff.PracticeSharp.Core namespace in another namespace you have to make it public and then create the library.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace BigMansStuff.PracticeSharp.Core
{
/// <summary>
/// .NET C# Wrapper to the SoundTouch Native C++ Audio library
/// </summary>
/// <see cref="http://www.surina.net/soundtouch/index.html"/>
public class SoundTouchSharp: IDisposable
{
//...
}
//...
}
Then in your project you have to add a using directive that allows to use that type from the namespace:
using BigMansStuff.PracticeSharp.Core;
You need to add a using statement to include the namespace that the class is defined in:
using BigMansStuff.PracticeSharp.Core;
Related
It can be seen and compiled inside the same file it is in inside the same project, the file is called default.aspx.cs.
However when I try to include the namespace in another file of the same project using the using DBConnStrings; statement -> I keep getting the compiler error "The type or namespace name 'DBConnStrings' could not be found".
The Code in the file which compiles called default.aspx.cs is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using DBConnStrings;
namespace DBConnStrings
{
public class GlobalStrings
{
public static string carSalesDBConnString =
ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString();
}
}
public void BindManu()
{
SqlConnection conn = new
SqlConnection(GlobalStrings.carSalesDBConnString); // Connect to Carsales database
conn.Open();
// .....
}
The other files can not see this namespace although they are in the same project.
How do I make them see it?
First of all, I'd suggest to put the method BindManu into the class, because I can't imagine this would work like that.
But to your problem: You have to specify the whole namespace. That means, if the file with the DBConnStrings namespace is in the folder test, you have to use using test.DBConnStrings to import the namespace. You should name the namespace like that as well to avoid confusion (namespace test.DBConnStrings).
But you actually don't have to specify the whole path, just the path within the project. That means, if your class is in C:\Users\Foo\Documents\Visual Studio 2017\Projects\BlaProject\DirectoryA\DirectoryB\MyClass with the project located in C:\Users\Foo\Documents\Visual Studio 2017\Projects\BlaProject, your namespace would be BlaProject.DirectoryA.DirectoryB. If the file your using isn't in your project folder, then you have to add a reference and use the path within the other project as above (but with another project name, obviously). If you want to add references, open the Solution Explorer, right click onto References, select add Reference, and select the reference to the project.
If you don't want to struggle with all that you can let vs do it for you. Simply type in the class you want from the other namespace, it will be marked as an error, click onto the lightbulb and select something like add using reference.
Furthermore, if you want to add a class to your project, don't do it with the explorer - simply right click onto the folder from your project you want to add the class to in your Solution Explorer, select Add, then New Item. In the popup select class and type in your name for the class. That's it!
I have created sample application as layers.
I have a layer which is under DataAccess namespace
using System;
using System.Data;
using DataAccess.DataAccessLayer; //This line is showing error
namespace AdapterClass
{
public class SchemaAdapter
{
}
}
Inside a file, intellisense of current namespace only available.
For ex:
In above example, intellisense of AdapterClass only available.
Be careful with your terms. A namespace is different than an assembly. If your data access class (and namespace) is in another project (say class library) then it is in a different assembly that needs to be referenced. To do that, you can:
Right click the project you shown the code above and right click References => Add Reference => Solution Tab => Click that project
If the current (most recent) item in the clipboard is a string, I want to take the string from the clipboard, and put each word in an array (just a simple loop which eliminates spaces and newlines, to take just words from the string). Then I simply want to print each item in the array (let's say each separated by a newline for testing purposes) to the terminal.
This is super easy, simple, etc. My trouble is that I cannot seem to find/use the Clipboard class that is built in to C#! Here is what I am using as my assembly references:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Object;
using System.Windows.Clipboard;
Note that the System.Windows.Clipboard; gets a red underline, because it is not lining up. Why could this be? http://msdn.microsoft.com/en-us/library/system.windows.clipboard.aspx shows the clipboard class information.
It's probably a fault on my end, but is it otherwise possible I have not set my paths correctly or something? I just installed Visual Studio 2012 For Desktop SP3 (although, I have had VS2012 for Web for quite some time, and it works properly).
System.Windows.Clipboard is a class and not a namespace, there is no point putting a class into a using directive.
The compiler error message should tell you the same.
First of all you must add a reference to System.Windows.Forms in your application. Go to Project -> Add reference, select System.Windows.Forms from .NET tab in the window that just opened. You must avoid the ThreadStateException by applying the STAThread attribute to your Main() function. Then you can use the Clipboard functions without any problems.
using System;
using System.Windows.Forms;
class Program {
[STAThread]
static void Main(string[] args) {
Clipboard.SetText("this is in clipboard now");
}
}
i hope this will help you
http://blog.another-d-mention.ro/programming/c/use-clipboard-copypaste-in-c-console-application/
it shows how to use the Clipboard functions in C# console application
You don't need this line: using System.Windows.Clipboard; using statements are for namespaces, and Clipboard is a class. That class is provided from the assembly PresentationCore.dll, and since you have WPF project, your project already has a reference to it.
You should have reference to System.Windows namespace only it has Class Clipboard in it.
You can set and get data from there
System.Windows.Clipboard.SetData();
You'll need a namespace declaration:
using System.Windows.Forms;
OR for WPF:
using System.Windows;
To copy an exact string
var dataObject = System.Windows.Clipboard.GetDataObject();
string text= dataObject.GetData("UnicodeText", true).ToString();
I have a Windows Form application. I've added a class to my project named MyLibrary.cs and I inherited this class of System.ComponentModel.Component and I've also added a bitmap image with its build action set to EmbeddedResource to my resources folder, but when I write the code below and build the project my customized icon does not change when I want to drag and drop my component to my Form. Would you please help me?
I've checked a lot of links like http://msdn.microsoft.com/en-us/library/system.drawing.toolboxbitmapattribute.aspx and How to find the elusive ToolboxBitmap icon but none of them worked for me!
Here is my code:
MyLibrary.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
internal class resfinder
{
}
namespace MyForm
{
[System.Drawing.ToolboxBitmap(typeof(resfinder),"MyForm.Bitmap1.bmp")]
public class MyLibrary:System.ComponentModel.Component
{
}
}
You should look here it says:
The bitmap must be 16x16
If you specify both a Type and a string, the control searches for an image resource with the name specified by the string parameter in the assembly containing the type specified by the Type parameter
So make sure your bitmap is located in the same assembly as "resfinder" and also put make sure in properties under build actions it is set as an Embedded Resource
I made the same ASP.NET C# project in both VS2010 and MonoDevelop using these two classes among the standard files (Site.Master, Web.Config, Default.aspx, etc.) and recieve this same error (CS0234) seen at the bottom.
Login.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using mynamespace;
namespace mynamespace
{
public partial class Logon
{
public void btnClicked(object sender, EventArgs e)
{
//ERROR IS HERE:
mynamespace.Test session = new mynamespace.Test();
//Obviously, this doesn't work either:
Response.Write(session.echoUser());
}
}
}
Test.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using mynamespace;
namespace mynamespace
{
public class Test
{
public string echoUser()
{
return "foobar";
}
}
}
I recieve the same error in both IDEs, here is the MonoDevelop error:
The type or namespace 'Test' does not exist in the namespace 'mynamespace' (are you missing an assembly reference?) (CS0234) Logon.cs
Basically, the class Test refuses to instantiate. Any input is appreciated!
If you have that Test class in an ASP.Net web project, then you need to place it in the App_Code folder, not just anywhere in the site.
You need to refer the projects to each other, if you haven't done so yet. I'm guessing that you don't get the intellisense to show the class in the other namespace, right?
You can see the References on the right side (most cases) under your project view. You can right click there and choose to Add reference. Then you browse to the binaries from the pther projects. (You might be able to point to the project itself too - I don't have VS in front of me at the moment.)
Also, It's a convention to use camel case for namespaces, so it should be MyNameSpace.
If the classes are in the same project, you might want to skip using mynamespace and refer to the class by Test intead of mynamespace.Test.
If these are both in the same project, please check that both files are included in the project and have the "Build Action" property set to "Compile". Please also check that all of these namespaces have exactly matching spelling and casing.