Questions tagged [field]

In computer science a field is a smaller piece of data from a larger collection.

In computer science, data that has several parts can be divided into fields. Relational databases arrange data as sets of database records, also called rows or tuples. Each record consists of several fields, also called attributes; the fields of all records form the columns.

In object-oriented programming, field (also called data member or member variable) is the data encapsulated within a class or object. In the case of a regular field (also called instance variable), for each instance of the object there is an instance variable: for example, an Employee class has a Name field and there is one distinct name per employee. A static field (also called class variable) is one variable, which is shared by all instances.

Source: Field (Computer Science) - Wikipedia article

Related tags:

5904 questions
35
votes
12 answers

Can awk deal with CSV file that contains comma inside a quoted field?

I am using awk to perform counting the sum of one column in the csv file. The data format is something like: id, name, value 1, foo, 17 2, bar, 76 3, "I am the, question", 99 I was using this awk script to count the sum: awk -F, '{sum+=$3} END…
maguschen
  • 765
  • 2
  • 8
  • 12
35
votes
6 answers

C#, immutability and public readonly fields

I have read in many places that exposing fields publicly is not a good idea, because if you later want to change to properties, you will have to recompile all the code which uses your class. However, in the case of immutable classes, I don't see why…
Benjol
  • 63,995
  • 54
  • 186
  • 268
35
votes
3 answers

Why is a `val` inside an `object` not automatically final?

What is the reason for vals not (?) being automatically final in singleton objects? E.g. object NonFinal { val a = 0 val b = 1 def test(i: Int) = (i: @annotation.switch) match { case `a` => true case `b` => false …
0__
  • 66,707
  • 21
  • 171
  • 266
34
votes
7 answers

What is the C++ equivalent of C#'s readonly field modifier?

Locking down state is great. In C# you can ensure that a field doesn't change it's value/reference once the constructor completes by declaring it as readonly. class Foo { private readonly string _foo; public Foo() { _foo =…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
33
votes
7 answers

Any reason to use auto-implemented properties over manual implemented properties?

I understand the advantages of PROPERTIES over FIELDS, but I feel as though using AUTO-implemented properties over MANUAL implemented properties doesn't really provide any advantage other than making the code a little more concise to look at it. I…
CptSupermrkt
  • 6,844
  • 12
  • 56
  • 87
33
votes
1 answer

how to get single field value in object list

how to get some field list in object list in kotlin fun main(args:Array){ println("Hello World") val list = listOf(member("hong",10), member("kil", 10)) } data class member(var name:String, var age:Int) Above code, I want to get…
Taehyung Kim
  • 610
  • 2
  • 7
  • 17
33
votes
7 answers

How to get the json field names of a struct in golang?

What is the way to get the json field names of this struct ? type example struct { Id int `json:"id"` CreatedAt string `json:"created_at"` Tag string `json:"tag"` Text string `json:"text"` AuthorId …
lambher
  • 433
  • 1
  • 4
  • 6
33
votes
2 answers

Java: How can I access a class's field by a name stored in a variable?

How can I set or get a field in a class whose name is dynamic and stored in a string variable? public class Test { public String a1; public String a2; public Test(String key) { this.key = 'found'; <--- error } }
ufk
  • 30,912
  • 70
  • 235
  • 386
32
votes
2 answers

Dynamically add fields to dataclass objects

I'm writing a library to access REST API. It returns json with user object. I convert it to dict, and then convert it to dataclass object. The problem is that not all fields are fixed. I want to add additional fields (which are not specified in my…
rominf
  • 2,719
  • 3
  • 21
  • 39
32
votes
3 answers

How do I assign by "reference" to a class field in C#?

I am trying to understand how to assign by "reference" to a class field in C#. I have the following example to consider: public class X { public X() { string example = "X"; new Y(ref example); new Z(ref…
Jamie
  • 837
  • 2
  • 8
  • 8
32
votes
2 answers

How can I define a list field in django rest framework?

Let's say I have a class class Tags(object): tags = [] def __init__(self, tags): self.tags = tags and a custom list field class TagsField(serializers.WritableField): """ Returns a list of tags, or serializes a list of…
user1876508
  • 12,864
  • 21
  • 68
  • 105
31
votes
5 answers

Terminology of Class "attribute" vs "member" vs "variable" vs "field"

It seems that developers often use these terms interchangeably when referring to a piece of data stored in an instance of a Class. Is there any technical difference between each term, or is it fine to use them interchangeably?
Josh Diehl
  • 2,913
  • 2
  • 31
  • 43
30
votes
2 answers

How can I make the HTML5 number field display trailing zeroes?

I have a field: I'd like to punch in 0.50 without it “correcting it” to 0.5, so it would display 0.50.
Tarang
  • 75,157
  • 39
  • 215
  • 276
30
votes
8 answers

Why won't anyone accept public fields in C#?

Seems like every C# static analyzer wants to complain when it sees a public field. But why? Surely there are cases where a public (or internal) field is enough, and there is no point in having a property with its get_ and set_ methods? What if I…
Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166
30
votes
7 answers

PHP - Getting the index of a element from a array

How can I get the current element number when I'm traversing a array? I know about count(), but I was hoping there's a built-in function for getting the current field index too, without having to add a extra counter variable. like…
Alex
  • 66,732
  • 177
  • 439
  • 641