Browsing 7239 questions and answers with Jon Skeet

How to pass DateTime.Ticks as URI parameter?

How can I get this code working? public ActionResult ABC(DateTime.Now.Ticks Id) { //some stuff return View(); } Your thoughts? EDIT The whole concept is have unique URLs for...
Jon Skeet
people
quotationmark

First, the basics: when declaring a method, you need to specify the type of the parameter, which in this case would be long: public ActionResult Abc(long id) { // ... } When you call that (whether internally or whether it's... more 3/5/2017 12:35:34 PM

people

My delegate type isn't working "Method name expected"

I tried this: class Program { public delegate int add(int x, int y); public class ff { public static int addNumbers(int x, int y) { return...
Jon Skeet
people
quotationmark

The type of your delegare variable is just Delegate. That could refer to any delegate. In order to invoke a delegate (in the normal way), you should have an expression of the appropriate type. After fixing the naming conventions and... more 3/4/2017 4:11:52 PM

people

Convert String With Zeros To Decimal

I have a string like this: "000123". I want to know how to convert this string to decimal but keep the leading zeros. I have used Convert.ToDecimal(), Decimal.TryParse &...
Jon Skeet
people
quotationmark

No, it's not. System.Decimal maintains trailing zeroes (since .NET 1.1) but not leading zeroes. So this works: decimal d1 = 1.00m; Console.WriteLine(d1); // 1.00 decimal d2 = 1.000m; Console.WriteLine(d2); // 1.000 ... but your leading... more 3/3/2017 7:26:30 AM

people

How do i check if a particular string is not present in a list in c#?

I have a list as follows, List<string> variablelist = new List<string> { "first", "second","third"}; And i have one more list, like List<string> method =...
Jon Skeet
people
quotationmark

LINQ is the simplest way of doing this, with the Except method: var inOnlyVariableList = variableList.Except(method).ToList(); The result will be a List<string> of strings which are in variableList but not in method. more 3/2/2017 11:51:41 AM

people

Is Java's import keyword for source files or binary files?

I know I can include a class or collection of classes in my Java project using the import statement. For example, import java.io.utils.* imports (i.e. makes available for use in...
Jon Skeet
people
quotationmark

Import just means "make the imported classes available by their simple names" - you can remove imports entirely if you use fully-qualified names everywhere. It's definitely not like #include in C for example. When you compile, if you try... more 3/2/2017 7:47:12 AM

people

List<PropertyInfo> except List<PropertyInfo> not working

I'm making a helper method where it would automatically set random values to a property of a given entity (class) so that I won't have to fill each property with a value when...
Jon Skeet
people
quotationmark

PropertyInfo "knows" which type you used to ask for it. For example: using System; using System.Reflection; class Base { public int Foo { get; set; } } class Child : Base { } class Test { static void Main() { ... more 3/1/2017 3:00:40 PM

people

narrow xdocument in c#

Is there any way to to cut off some part of xDocument and still getting xDocument? By cutting off I mean keeping selected node. I have XML like this: <something 1> ...
Jon Skeet
people
quotationmark

You mean you want only the first child node? Yes, that's simple using the Remove extension method: doc.Root.Elements().Skip(1).Remove(); Sample: using System; using System.Linq; using System.Xml.Linq; class Test { static void... more 3/1/2017 9:35:52 AM

people

Int array as a key in a Dictionary VS a string

I have a dictionary right now that is using a string as the Key, and a GameObject as the value. The strings are all IP address's, so they are not very long. Here is an...
Jon Skeet
people
quotationmark

As ever, you should test performance rather than guessing about it or asking others to guess. However, two things to think about: You've shown an IPv4 address... what about IPv6? That could definitely complicate things The IPv4 address... more 2/28/2017 3:58:48 PM

people

Two threads referring one variable

I am running the below class . public class RunThreads implements Runnable { static int i; public static void main(String[] args) { RunThreads job = new...
Jon Skeet
people
quotationmark

Things are scary when you access shared data with no synchronization etc: There's no guarantee that the Alpha thread reading i will see the "latest" update from the beta thread or vice versa It's possible for both threads to start i++ at... more 2/28/2017 2:41:09 PM

people

Recursive method wont loop childs children

I´m trying to create a recursive method to create a menu. The menu I want to achieve displays the childrens children and so on. I´ve debugged the code and it goes all the way down...
Jon Skeet
people
quotationmark

Each time you call GetMenu, you're creating a new StringWriter - but you're ignoring the return value from your recursive calls. The simplest fix would probably be to change it to: public string GetMenu(Node currentPage) { var... more 2/28/2017 1:22:30 PM

people