How to use BigInteger in VS 2010 - c#

I have been trying to use the BigInteger type, that is supposedly new in .NET Framework 4.0.
I don't seem to be able to get to it, and get an error when trying to reference it via Using System.Numerics.
Any idea what I'm doing wrong? Sorry if this is a stupid question...

Add a reference to the System.Numerics assembly to your project.
a. In Solution Explorer, right-click the project node and click Add Reference.
b. In the Add Reference dialog box, select the .NET tab.
c. Select System.Numerics, and then click OK.
Add a using directive importing the System.Numerics namespace:
using System.Numerics;
Use the BigInteger structure:
var i = new BigInteger(934157136952);

Did you add a reference to System.Numerics?
Right click on References -> Add Reference -> .NET tab -> System.Numerics -> OK

Add a Reference to System.Numerics assembly.
Add using System.Numerics; statement

Have you added a project reference (Project... Add Reference...) to System.Numerics?

Related

I'm getting error that i'm missing a reference but which one?

I added to the top of the form
using mshtml;
IHTMLDocument2 doc = (IHTMLDocument2)webbrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
The error is on:
(IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
Error 3 One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?
Do remember that just by adding the statement Using mshtml; (considering that all the types used falls under mshtml dll) will not bring in the referenced dll. You will also need to add the reference of the dll to your project Reference folder.
Make sure you have done that.
You need to add a reference to the Microsoft.mshtml assembly. Follow these steps to do so:
Project → Add Reference
Go to the Extensions tab (under Assemblies) on the left
Make sure the checkbox next to Microsoft.mshtml is checked.
Press OK.
Now everything should work fine.
You may see more than one entry for Microsoft.mshtml in the listed assemblies. In that case select any one of them (preferably the newest version).

How to convert object to JSON without JSON.NET library?

I want to save this object:
Student s = new Student();
to Json file. But Visual Studio 2012 can't find none of these namespaces:
System.Web.Script;
System.Json;
System.Runtime.Serialization.Json;
Any idea?
If you want to serialize class into Json you can try this one too:
Install JSON.NET if you haven't yet.
make sure to include using Newtonsoft.Json;
and you can try this code:
Student s = new Student();
string json = JsonConvert.SerializeObject(s);
sorry for my bad english.
Step 1: Google "System.Runtime.Serialization.Json Namespace" and find this page:
System.Runtime.Serialization.Json Namespace
Step 2: Click on the class you are interested in ( let's say JsonReaderWriterFactory Class )
Step 3: Read the part that says what assembly that class is in:
Assembly: System.Runtime.Serialization (in
System.Runtime.Serialization.dll)
Step 4: Add that DLL as a reference to your project. See: How to: Add or Remove References By Using the Add Reference Dialog Box
Step 5: Repeat Steps 1 - 4 as needed.
Make sure you add the appropriate references to your project. For example, to use the datacontractjsonserializer class, you need to add a reference to System.Runtime.Serialization to your project.
If you're using visual studio, read How to: Add or Remove References in Visual Studio.
You can then use it with:
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Student));
ser.WriteObject(outputStream, student);
Of course there are many other ways to do this and I won't go into detail about each one (I'm sure you've found some examples since you listed those namespaces).
TIP: if you want to use a .NET class and you're not sure what reference you need to add to your project in order to use it, open up the MSDN page for the class and look for the text like:
Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)
That's the assembly reference you need to add to your project.
The other answers are correct in saying that you need to add references to the appropriate assemblies. As an easy way to manage references for a personal project, I'd recommend NuGet, a package manager for Visual Studio. Thankfully, NuGet ships with Visual Studio 2012, so you just have to right-click the project, click on "Manage NuGet packages", and search for Json.NET. The first blog post I found on using NuGet in Visual Studio 2012 is here, and it seems to give a nice set of instructions, complete with screenshots.
You probably need to add references to your project:
System.Runtime.Serialization.Json is in System.Runtime.Serialization
System.Web.Script is in System.Web.Extensions
System.Json is only for Silverlight

WeakEventManager class not found

I'm attempting to inherit from the WeakEventManager class but the namespace can't be found in my project. I'm not sure what's going on as I have the using System.Windows; directive. I can load a project that uses this class successfully I just can't seem to implement it on my own. The project is .Net 4.5 and I'm unsure as to what's happening.
Any help is appreciated. Thanks in advanced.
The class lives in the System.Windows namespace, but is defined in the WindowsBase assembly. Make sure you have imported the WindowsBase assembly and added it as a reference to your project.
In Solution Explorer
open your project
right-click on References
click Add Reference
select .NET tab
select System.Windows
click OK
In Solution Explorer
open your project
right-click on References
click Add Reference
select .NET tab
select WindowsBase

can't find using System.Web.UI.HtmlControls namespace

I tried every way to use System.Web.UI.HtmlControls; but I didn't find any reference for that.
How can I use that namespace?
Go to your References for your project and ensure System.Web is in there. If not, Right click, Add Reference, .NET, and add System.Web
you need to right-click the project -> properties -> then change the "Target framework" which will probably be ".NET Framework 4 Client Profile" to just ".NET Framework 4".
Browse to C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll and pick it up from there as a reference

Why do I get a compile error when calling string.Select in C#?

In a different question (How to split a number into individual digits?), they call the Select method on a string. This site also suggests that it is possible.
However, when I try to do this using the code samples found in either of those places, I get a compile error. What could be causing this, and how can I use the Select method on a string?
This is a LINQ method.
To use it, you need to be using .Net 3.5 or later, have referenced System.Core.dll, and have using System.Linq.
Are you sure you have included the System.Linq reference?
using System.Linq;
Just Add a reference system.core.dll
1.In Solution Explorer, right-click on the project node and click Add Reference.
2.In the Add Reference dialog box, select the tab indicating the type of component you want to reference.
3.On .NET tab Select System.Core, then click OK.
And add using System.Linq on what the example you provided;
and make sure that youre project framework is 3.5 because it will not work on lower versions.
Regards

Categories

Resources