readonly

Read only two-dimensional array in C#

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 07:28:00
问题 Is there any established way of returning a read-only 2-d array in C#? I know ReadOnlyCollection is the right thing to use for a 1-d array, and am happy to write my own wrapper class that implements a this[] {get} . But I don't want to reinvent the wheel if this wheel already exists. 回答1: There's only one way to simulate this. You need to create your own class, with a private array. The most similar implementation of an array is an indexer: Using indexers Indexers (C# programming guide) 10.8

Read-Only Field in Django Form

為{幸葍}努か 提交于 2019-12-23 06:53:25
问题 How do I set a field to read-only in a Django form? I know how to disable a field but that's not what I'm looking for. Any help would be appreciated. 回答1: You can use the optional attrs parameter when defining the Field . To wit: somefield = forms.CharField( widget=forms.TextInput(attrs={'readonly':'readonly'}) ) 回答2: In django 1.9 in a Field.disabled attribute available : https://docs.djangoproject.com/en/1.9/ref/forms/fields/#disabled The disabled boolean argument, when set to True,

Showing D Coverage Results as Overlays in Source Buffer

风格不统一 提交于 2019-12-23 03:32:22
问题 The D language compiler DMD outputs its coverage analysis in a file containing the original source as | inout(Ix)[] prefix() inout | { 2037| assert(!keys.empty); 2037| final switch (keys.length) | { 000000000| case 1: 000000000| return keys.at!0[]; 2037| case 2: | import std.algorithm.searching : commonPrefix; 2037| return commonPrefix(keys.at!0[], keys.at!1[]); | } | } that is, the original source where each line has been prefixed by a 10-character column containing the execution count (if

Does Tomcat cache compiled JSP pages in memory if scratchdir is read-only?

谁说胖子不能爱 提交于 2019-12-23 02:54:40
问题 I've got a webapp installed in a Tomcat container that exists on a read-only file system. As a result, I'm seeing this message (actual names changed to protect the guilty) on startup: SEVERE: The scratchDir you specified: /readonlyfs/tomcat/work/Catalina/localhost/myApp is unusable. Despite this message, the app seems to run, and it's difficult to tell for certain, but it appears that JSP pages are not being compiled for every access. So, my question is, what happens to the compiled JSP pages

How to Create a Read-Only Object Property in C#?

爱⌒轻易说出口 提交于 2019-12-22 09:13:47
问题 As can be seen below, the user is able to change the readonly product field/property: class Program { static void Main(string[] args) { var product = Product.Create("Orange"); var order = Order.Create(product); order.Product.Name = "Banana"; // Main method shouldn't be able to change any property of product! } } public class Order { public Order(Product product) { this.Product = product; } public readonly Product Product; public static Order Create(Product product) { return new Order (product

Setting readonly fields (Is this bug?)

可紊 提交于 2019-12-22 03:49:12
问题 While just playing with c#, realized a strange thing. Here is the code: class Program { static void Main(string[] args) { System.Diagnostics.Debug.Write(string.Empty); typeof(string) .GetField("Empty", BindingFlags.Static | BindingFlags.Public) .SetValue(null, "Tolgahan"); Console.WriteLine(string.Empty); // output : Tolgahan } } Why reflection let us to change readonly fields? The question is "why the setting via reflection is allowed", not "how to do it", so it is not a duplicate of Can I

Programmatically Changing ReadOnly Mode on DataGridView Rows

元气小坏坏 提交于 2019-12-21 12:31:47
问题 Without explaining the entire context, my problem is basically this: I have a datagridview on a Windows Form which is bound to an Entity Framework DbSet: dbSet<TEntity>.Local.ToBindingList() . If I set the datagridview's ReadOnly property to true (in design view), and then have this statement in my code: myDataGridView.Rows[rowIndex].ReadOnly = false; It steps right through without changing the value! (And no, my datasource is not readonly.) Looping through the cells in the row and setting

Static string literal table?

坚强是说给别人听的谎言 提交于 2019-12-21 03:41:04
问题 What is the correct way in C++ to create a global & static table of strings? By "global", I mean: Useable from any file that includes the header. But not part of some run-time created singelton objcet. By "static", I mean: As little run time set up possable. Data in read only memory pages. Only 1 instance of data per app. By "string", I mean: Null terminated array of chars is fine. std::string would be nice, but I don't think it can be done in terms of the above. Correct? By "table", I mean:

What does immutable and readonly mean in C#?

与世无争的帅哥 提交于 2019-12-21 03:34:40
问题 Is it correct that it is not possible to change the value of an immutable object? I have two scenarios regarding readonly that I want to understand: What if I have a collection and mark it as readonly , like the following. Can I still call _items.Add ? private readonly ICollection<MyItem> _items; And also for the following variable, if later on I call _metadata.Change which will change the internal values of a couple member variable in the Metadata instance. Is _metadata still immutable?

Write-Only pointer type

亡梦爱人 提交于 2019-12-20 08:33:30
问题 I'm writing software for an embedded system. We are using pointers to access registers of an FPGA device. Some of the registers are read-only, while others are write-only. The write-only registers will produce undefined values when read. I want to define a pointer type that will allow the compiler to detect when reading values from a write-only registers (a.k.a. dereferencing). Can a write-only pointer be created using only C language syntax? (We are developing first prototype using C, but