I come from a VB.Net environment, where using Imports System and then IO.Directory.GetFiles(...) works.
On the other hand, it seems that using System; is not sufficient to write use IO.Directory without prefixing it with System.. The only workaround seems to be
using IO = System.IO;
Why?
Example code:
using System;
using System.IO;
namespace Test {
class Program {
static void Main(string[] args) {
System.Console.WriteLine(IO.Directory.GetFiles(System.Environment.CurrentDirectory)[0]);
}
}
}
Edit: My question is not what should I do to get my code working, but specifically "why cant I write IO.Directory.GetFiles ??"
Add
using System.IO;
and you'll have the behavior you expect. C# does not make child namespaces available without a using directive (or full qualification.)
The thing you are talking about is not posssible in C# that might be diffrence between C# and vb.NET.
If you are converting vb.Net code to C# than make use of this site will help you lot
vb.net to c#
Code fo ryou
System.IO.Directory.GetFiles(...)
or add
using System.IO;
will do for you
Related
I am currently working on a small program, that loads an image file into the Console and print it out as an asci image. I am using the ".Net Console application framework 4". My Problem is, that I do not know how to create a Bitmap. After browsing for a while, I found many answers to my question, that suggested the "System.Drawing.Bitmap" class. When I try to refer to this class, visual studio does not even know System.Drawing.Bitmap. I have a class "AsciArt" which should convert the picture in the method ConvertToAsci. Does anybody know what my mistake is?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Bitmap;
namespace consoleGrafix
{
class AsciArt
{
private string ImgLink;
public AsciArt(string imageLocation)
{
this.ImgLink = imageLocation;
}
public void ConvertToAsci(string saveLocation)
{
var bm = Bitmap(saveLocation);
}
}
}
The solution was to set up my class by inheriting from image class. Also, in the ConvertTo Asci method, there was a "new". https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=netframework-4.0 . This really helped. Thank you!
So I have two dlls, Algorithms.dll and Data_Structures.dll (I made these from projects I found on GitHub). Using the browse feature I have managed to add both of the DLL files as references to my Visual Studio 2017 console project. The problem is I can't do anything else with them. Whenever I try to reference something within either file, it simply cannot be found. The only thing that is recognized is the namespace, but nothing inside of that.
What do I need to do to get VS to find the classes these DLLs contain so I can use them? I am aware I need to use Algorithms.Sorting for the example but I can't call anything so I used this as an example.
P.S. If you need more info, please ask. I'm not sure what's relevant to this issue.
EDIT: Ok, it was misleading to have that kind of example. Corrected but please read the question.
EDIT: I tried this on Monodevelop and get the same issue. Maybe it's not the IDE that's the problem?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Algorithms.Sorting; // Error, Sorting cannot be found, and neither can the file container Sorting
using Data_Structures; //Perfectly ok, can find the namespace
namespace CS_HW2_Testing_App
{
class Program
{
static void Main(string[] args)
{
// I'd like to call MergeSort and so forth here. What am I missing?!
}
}
}
Here's the top piece of the file containing MergeSort if it helps
using System;
using System.Collections.Generic;
using Algorithms.Common;
namespace Algorithms.Sorting
{
public static class MergeSorter
{
//
// Public merge-sort API
public static List<T> MergeSort<T>(this List<T> collection, Comparer<T> comparer = null)
{
comparer = comparer ?? Comparer<T>.Default;
return InternalMergeSort(collection, 0, collection.Count - 1, comparer);
}
...
In the first code block, you're importing the wrong namespace: using Algorithms.MergeSort should be using Algorithms.Sorting. Then you can use MergeSorter.MergeSort<T>(...) in your code!
You need to reference the namespace not the class.
using Algorithms.Sorting; //instead of using Algorithms.MergeSort;
Plus make sure the classes are public
I'm currently doing a project where I have to use the Affectiva SDK to analyse some videos that I have recorded. I have downloaded the files, which they have given me and started writing the code for the SDK to work, however when calling the callback functions in my code, Visual Studio doesn't seem to accept the arguments that are put in. So I figured that the interfaces for the callback functions must be done. I'm not really clear on how to this though, since I thought this was all done in their assembly code. My code so far looks like this:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Affdex;
namespace ConsoleApplication2
{
class Program
{
public interface FaceListener { }
public interface ImageListener { }
public interface ProcessStatusListener { }
static void Main(string[] args)
{
VideoDetector detector = new VideoDetector(15);
String licensePath = "C:/Users/hamud/Desktop/sdk_ahmedmudi1992#gmail.com.license";
detector.setLicensePath(licensePath);
String classifierPath = "C:/Programmer/Affectiva/Affdex SDK/data";
detector.setClassifierPath(classifierPath);
detector.setFaceListener(this);
detector.setImageListener(this);
detector.setProcessStatusListener(this);
detector.setDetectSmile(true);
detector.setDetectSurprise(false);
detector.setDetectBrowRaise(false);
detector.setDetectAnger(false);
detector.setDetectDisgust(false);
detector.setDetectAllExpressions(false);
detector.start();
detector.stop();
}
}
}
As far as I know, I have to write code for the interfaces if I'm not mistaken... Or do I? Please help.
Here is a tutorial on getting started to analyze the video files.
As far as I know, I have to write code for the interfaces if I'm not mistaken... Or do I?
No you don't. You just have to implement the methods in the interfaces if you were to use them.
Here is the link to the sample app that uses Camera Detector which you can relate to since both the Camera Detector and the Video Detector implement the FaceListener, ProcessListener and ImageListener Interfaces.
EDIT: You have to implement the Listeners. For example in the code sample you are using the FaceListener so you need to write the implementation for the callbacks viz onFaceFound() and onFaceLost().
You may also want to create an object of processStatusListener and wait for the process to end for a video file something like this:
AffdexProcessStatusListener processStatusListener = new AffdexProcessStatusListener();
processStatusListener.wait();
Here is a link to our C# app AffdexMe which uses CameraDetector. You may find examples of CameraDetector, PhotoDetector, VideoDetector and FrameDetector in our getting started guide.
I'm trying to use the Process class but it gives me this compiler error every time I do
The name 'Process' does not exist in the current context
I've already added using System.Diagnostics; at the top of my code but I still get this error. Autocomplete wont even recognize the class.
Hear is the code. I've only included the Main method because the rest of the code has nothing to do with the error.
using System;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
public class MainClass
{
static void Main()
{
AIRuntime adam = new AIRuntime("Adam", false);
adam.AIUpdate();
Process.Start(adam.directory); //adam.directory is just a string
}
}
My IDE is Xamarin Studio if it matters.
After web searching and attempts, I found the problem.
To fix this, I manually add a reference to System in my project options instead of just typing using System;. I also need to keep using System.Diagnostics; at the top. It's all in the picture below
Thanks guys for trying to help
I am trying to get the HashLib library # https://hashlib.codeplex.com/ working for the new SHA-3 Keccak algorithm. I've written a simple Console application that supposedly has to output the correct hash code, but it doesn't!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using HashLib;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
{
string passPhrase = "";
IHash hash = HashFactory.Crypto.SHA3.CreateKeccak512();
HashResult r = hash.ComputeString(passPhrase, System.Text.Encoding.ASCII);
Console.WriteLine(r.ToString().ToLower().Replace("-",""));
Console.WriteLine("{0}, {1}, {2}", hash.BlockSize, hash.HashSize, hash.Name);
Console.ReadLine();
}
}
}
}
The application builds and runs ok, but the output is very wrong. When I use other people 's implementations of the Keccak algorithm, I get different results and it doesn't match for example this wiki post either. https://en.wikipedia.org/wiki/SHA-3 So something is obviously wrong.
When I leave the text empty, as per example, I get the following: "df987cfd23fbc92e7e87faaca300ec3f etc. etc." while the wiki and other tools say I should get
"0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e"
,which is something entirely different. I also tried it with non-empty strings of course.
Does anyone have a suggestion?
Your version of HashLib is too old. If you look at the recent changes you can see the test vector changed from the one you got to the one you should get. (The algorithm changed as well, of course.)