It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm trying to access the Scoop.it API via C# to retrieve posts in topics. It's pretty much straight forward, in PHP, how are objects managed in C# and how to you access the properties?
Here's the php code which i'd like to get a C# equivalent of:
$topic = $scoop->topic(24001);
foreach($topic->curatedPosts as $post)
{
echo $post->title;
}
I couldn't find an API reference for Scoop.it in C#, but I would imagine that they conform to the naming standards in C#.
So the PHP code converted to C# would looke like this:
var topic = scoop.Topic(24001);
foreach(var post in topic.CuratedPosts)
{
Console.WriteLine(post.Title);
}
However echo in PHP prints something out to the web-page, so I would imagine that you want to replace Console.WriteLine with Response.Write.
If you have a class that looks like this, where Name is a property:
class Topic
{
public string Name { get; set; }
}
Then you would create an instance of Topic like this:
var topic = new Topic();
Now you can access the property Name like this: topic.Name
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a model witch is holding different values in my website and i am currently trying to retrieve the value token.
I call my model in the following way:
HoldToken t = new HoldToken();
string token = t.Token;
This is how the model looks
namespace MvcResComm.Models
{
public class HoldToken
{
public string Token { get; set; }
}
}
I am always receiving null as my returned token. I think this is because i am using the new keyword.
How can i instantiate the model HoldToken with out newing it?
Most likely, you're using a constructor-less class and an automatic property.
I'd guess that you're not setting the HoldToken automatic property, which is why you're getting the null.
Add a new parameterless constructor and make sure the Token member is initialised in some way.
public HoldToken()
{
// Set value of token here
// Guessing at how you'd instantiate it.
Token = new Token();
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm trying to put this string in my resources:
Environment.CurrentDirectory + \\Server Files\\
But whenever I load the string, the Environment.CurrentDirectory part is shown as normal text instead of the current directory path :(.
Example:
Console.WriteLine(Resources.ServerFilesLocation); // Doesn't give me a path, but just plain text.
Any runtime environment value cannot be stored as a string in resources. What you should do is create a layer between. Something like:
static class ResourceManager
{
public static string ServerFilesLocation {
get {
return String.Format(Resources.ServerFilesDirectory, Environment.CurrentDirectory);
// ServerFilesDirectory = "{0}\\Server Files\\" or something similar
}
}
}
And use it like: Console.WriteLine(ResourceManager.ServerFilesLocation);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have php code that puts some values into an Array as follows:
$hunter=addslashes($MessageArray[1]);
$time=addslashes($MessageArray[2]);
I wrote the same code in C# and wanted to know if it was correct.
string Hunter = Messagearray[1].tostring();
string time = Messagearray[2].tostring();
As James mentioned, use Pascal casing:
string hunter = messageArray[1].ToString();
string time = messageArray[2].ToString();
Also, C# arrays are indexed starting at 0. You can change the starting index of arrays in PHP, but you can't in C#. Perhaps you do wish to take the 2nd and 3rd items, but keep it in mind. You might want:
string hunter = messageArray[0].ToString();
string time = messageArray[1].ToString();
As far as addslashes() goes, it will depend on your usage of hunter and time. If you're using them in a SQL statement, there are other ways of accomplishing the functionality of PHP's addslashes().
Snipped from Here
public static string AddSlashes(string input)
{
return System.Text.RegularExpressions.Regex.Replace(input, #"(\\)([\000\010\011\012\015\032\042\047\134\140])", "$2");
}
Usage:
//
var Messagearray = new object[] { "item 0", 1 };
var hunter = AddSlashes(Messagearray[0].ToString());
var time = AddSlashes(Messagearray[1].ToString());
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Scenario:
I have to check for user input (a string) that shouldn't contain <.%?/ symbols and if it does I remove them. I have 20 different places where I've to check it, actually, 20 different pages with each 20 different controls.
So I wrote a function like the following shortened example:
public string MyFunction (string userinput)
{
return userinput.replace("<"," ");
}
Now if I want to call this function from within another function and there's an error in this function's try catch block I want it to write an error to a Label on the main page, without interrupting the second function.
Also i am thinking of implementing conditional statement function calls too.
Usually it's best to let the calling function catch your error and to act upon it. Something like this (assuming C#, but your question wasn't clear about that and didn't have a working example):
try {
string resplacedString = yourReplaceFunction(userInput);
} catch (MyException e) {
Label1.Text = "An error occurred." + e.Description;
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a flash file, but I haven't got the source codes.
How can I get values from it?
For example if it was a html form, I can get the posted values like below:
Request.Form("myValue")
But it doesn't work. How can I get the posted values?
Thanks.
In HTML, this code:
Request.Form("myValue")
Is not accessing the HTML source code; it's accessing the data sent in an HTTP form post. In HTML, the input names happen to dictate which form variables are sent.
ActionScript (the Flash programming language) can do a post just like HTML. Here's some sample code:
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("yourpage.aspx");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.myValue = "foo";
loader.addEventListener(Event.COMPLETE, handleCompletion);
loader.load(request);
private function handleCompletion(e : Event):void {
// Do things after the post completes
}
If you post to an ASP.NET page or handler using this code, Request.Form("myValue") would work the same way as if an HTML form had been posted.