Browsing 7239 questions and answers with Jon Skeet

Why would we use BufferedStream for setting Buffer Size

We can set the buffersize for Reading a File in FileStream itself. FileStream fs=new FileStream(path,FileMode,FileAccess,FileShare,1024); ...
Jon Skeet
people
quotationmark

So why would we need BufferedStream if we can set buffer size in FileStream itself. Because not every stream is a FileStream. What about NetworkStream? Or some other arbitrary stream? Or a situation where the code that needs buffering... more 10/18/2013 12:12:18 PM

people

How I get the Attributevalue from a Xml to a Array with Linq to XML?

hi i want to get a arralist from a xml file with Linq to XML here my xml: <?xml version="1.0" encoding="iso-8859-1"?> <modules> <modul...
Jon Skeet
people
quotationmark

I suspect you want: private List<string> GetModules() { return XDocument.Load(Server.MapPath(@"~\App_Data\UGNX.xml") .Root // Root element .Elements("modul") // Select child... more 10/18/2013 10:59:26 AM

people

Generic Get method does not include FK's?

I'm trying to create a generic GetAll method that works for each of my model classes in my ASP.NET MVC4 project. Here's my code: public static List<T> GetAll(params...
Jon Skeet
people
quotationmark

I can't say I've used EF myself, but in general LINQ doesn't mutate queries when you call a method - instead it returns a new query. So if you change your code to: DbQuery<T> entities = db.Set<T>(); foreach (var... more 10/18/2013 10:05:13 AM

people

How to present a character Unicode with 5 digit (Hex) with c# language

I want to print a Unicode character with 5 hexadecimal digits on the screen (for example to write it on a Windows Forms button). For example, the Unicode of the character Ace...
Jon Skeet
people
quotationmark

You can use the \U escape sequence: string text = "Ace of hearts: \U0001f0b1"; Of course, you'll have to be using a font which supports that character... As an aside, I'd strongly recommend avoiding the \x escape sequence, as they're... more 10/18/2013 8:49:34 AM

people

Get the value of a static property from a System.Type

I have the situation that I am trying to access a static property that contains a singleton to an object that I wish to retrieve only by knowing its type. I have an implementation...
Jon Skeet
people
quotationmark

You can simplify it slightly by calling PropertyInfo.GetValue instead: SelectedValue = (IFace)SelectedType .GetProperty("Instance", BindingFlags.Static | BindingFlags.Public) .GetValue(null, null); As of .NET 4.5 you could call... more 10/18/2013 8:30:47 AM

people

Does using text properties cause memory leaks?

If a string is immutable, and the Text property of a text box is a string type, will that not result in a massive memory leak if my application makes a lot of changes to the text...
Jon Skeet
people
quotationmark

(I'm assuming you're talking about Java or .NET.) will that not result in a massive memory leak if my application makes allot of changes to the text box No. It may require many strings to be created, but they can then be garbage... more 10/18/2013 6:37:03 AM

people

Explain the output of java code containing interfaces

I had come across a question for which I am not able to find out why its output is coming as 7 when I calculate mathematically it can produce output as 7, 8 or any other...
Jon Skeet
people
quotationmark

Obviously code like this should never actually occur. It's horrendous. I don't think you should spend too much time worrying about why it gives 7, but it's actually not too hard to see why. The first field value to be evaluated is... more 10/18/2013 6:22:12 AM

people

Compiler inconsistent accessibility error with passing nested class as a function parameter

My visual studio 2010 finds inconsistent accessibility of parameter type error when I compile this C# code: class Program { class BaseClass { public class...
Jon Skeet
people
quotationmark

Top-level types default to being internal, but nested types default to being private. You've therefore got an internal type with a public method that has a private type as a parameter. Making all the access modifiers explicit: internal... more 10/18/2013 5:52:27 AM

people

Create a decimal value for timer on how long until next tick

I want to create a 0 to 1 value that I will get from my timer. The value will describe how long it is until the next tick. 0 is the furthest away from the tick (in milliseconds)...
Jon Skeet
people
quotationmark

One simple option would be to use a Stopwatch. Start it when you start the timer, and call Restart at the start of each tick handler - indeed, you can do this separately by adding a handler just to do the stopwatch restart before you add... more 10/17/2013 10:33:36 PM

people

Unity 4 C# IndexOutOfRangeException: Array index is out of range

Apologies if this is answered somewhere else but I believe my problem is very specific and I haven't got the slightest clue, based on past experience in python, why this code...
Jon Skeet
people
quotationmark

This is the problem: MissionTemplate[] MISSION = new MissionTemplate[gen]; for (int i = 1; i <= gen; i++) { ... MISSION[i] = new MissionTemplate(); Aside from violating normal naming conventions, arrays in C# are 0-based -... more 10/17/2013 9:11:08 PM

people