|
The property name is just syntactical sugar provided by the compiler. The only time it appears in the compiled code is in the TupleElementNames attribute.
If you were using a compiler that didn't understand that attribute - for example, ASP.NET without the Roslyn NuGet packages installed - you would only have access to the raw ItemN properties.
It's somewhat similar to how LINQ works; the compiler takes the C# code you've written, and transforms it into IL code that the JIT compiler will understand. The JIT compiler doesn't need to know anything about query statements, or extension methods, or even iterator methods.
If you use something like LINQPad[^] to examine the IL, you'll see something like this:
var vtp = VTProp;
Console.WriteLine("S2: {0}", vtp.S2); ⇒
ldarg.0
call UserQuery.get_VTProp
stloc.0
ldstr "S2: {0}"
ldloc.0
ldfld System.ValueTuple<System.String,System.Int32,System.String>.Item3
call System.Console.WriteLine ⇒
ValueTuple<string, int, string> vtp = VTProp;
Console.WriteLine("S2: {0}", vtp.Item3);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I read what you write carefully, but, this does not address the "facts" presented by what I observe.
The digression about what will not happen in another flavor of the .NET compiler has what bearing on this topic ? Of course, new syntactic features are not available in other/previous versions of .NET.
The code I showed demonstrates the availability of ValueTuple field Names at run-time; the fact this is a result of the compiler's action, and does not show up in the IL, is understood.
There's a whole lot of .NET features that don't appear in the IL ... which seems like a like a tautology to me: what else would the IL be if it were not a distilled-to-the-metal (but, still abstracted from actual hardware) representation
Understanding how ValueTypes, and their optional field Names, work is, imho, not furthered by statements that do not match observed run-time behavior.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
BillWoodruff wrote: at run-time
The point is, your C# code is not what's executing at run-time. What's executing at run-time is the (machine code compiled from the) MSIL generated by the C# compiler.
If you've ever looked at the run-time version of an iterator method, or an async method, you'll see that the run-time MSIL often bears little resemblance to the C# you wrote.
The ValueTuple field names are not available at run-time. They are only available to the Roslyn compiler.
Or perhaps I've misunderstood what you mean by the phrase "run-time"?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Or perhaps I've misunderstood what you mean by the phrase "run-time"? Evidently, yes
I mean exactly what this example proves:
public (string S1, int I1, string S2) VTProp {set; get;} VTProp = ("hello", 23, "exit");
var vtp = VTProp;
string s2 = vtp.S2; At run-time the third field of the ValueTuple can be accessed by its field Name 'S2 without error.
QED
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
OK, we're obviously talking about different things.
At run-time - when the code is running - your C# code is nowhere in sight. All that exists is the MSIL code, which is the result of various transformations applied by the C# compiler.
The fact that you can write and compile code which uses the named field doesn't mean that the named field is available when the code is running. It just means that the compiler understands it, and knows how to transform it into something that will work at runtime.
If you want to try accessing it when the code is running, try using reflection, or dynamic . You'll see that the named field is not available.
Type t = VTProp.GetType();
Console.WriteLine(t.GetField("S2"));
foreach (FieldInfo field in VTProp.GetType().GetFields())
{
Console.WriteLine(field.Name);
}
dynamic vtp = VTProp;
Console.WriteLine("S2: {0}", vtp.S2);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
tell me
modified 22-Feb-18 15:55pm.
|
|
|
|
|
Whatever you mean by "data recovery", it isn't simple job. You'll need to know how to access to different file systems to be able to recover a piece of data. The best results is when you know how to access to raw data (no matter of file system).
See: Data recovery - Wikipedia
|
|
|
|
|
Message Closed
modified 22-Feb-18 15:55pm.
|
|
|
|
|
Member 13685821 wrote: i need coding for c# to make recovery software
Well then you'd better get crackin'. Software doesn't write itself, you know!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Then you have to study and understand how both these filesystems are organized, and begin to code with these understandings.
I would add that C# may not be the best choice for this task, since it adds several layers of abstractions between the code and the core I/O operations that you would need. And, finally, this is far from a trivial task; if you have to ask this on a public forum, you are probably not fit yet for this.
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
"Recovery" implies a "backup" was created in the first place.
Do you have a backup procedure?
Or is this another "PC Cleaner"? (i.e. doesn't really do anything)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
First off, NOBODY is just going to hand you a quite large piece of code to do this.
Second, if you're even asking this question, you're not yet qualified to even attempt it.
You MUST understand how the various file systems work, how they are organized both logically and on disk, the various types of partition tables, how they work, the various disk structures, what actually happens when you do any operation to a file or to the file system itself, what can go wrong with them, how to handle cases where a file system maintains backups of it structures, ...
Yeah, you've got about a years worth of homework to do, maybe more, before you even attempt to write something like this.
Oh, and you're not going to write it in C#. A much better language would be C so you can run the app without a dependency on a working O/S and a rather large runtime environment.
|
|
|
|
|
How to get an answer to your question
Be specific!
Don't ask "can someone send me the code to create an application that does 'X'.
Pinpoint exactly what it is you need help with.
Director of Transmogrification Services
Shinobi of Query Language
Master of Yoda Conditional
|
|
|
|
|
Hi Team,
DateTimePicker control has the below menu options on Mouse Right Click :
Cut
Copy
Paste
No Date/Time
We can select any of this from the menu
Can anyone let me know how can i trigger this clicked events ?
Tried below code:
private void dateTimePicker_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
}
}
Thanks
Sharan
|
|
|
|
|
This Behaviour didn't come from the Control - it comes from the ContextMenu you have assigned to the Control - so you have to look for the Events of this ...
|
|
|
|
|
Hell everyone when i try to insert data through the c# windows application i got "InvalidOperationException" below i have attached my codings can any one help me?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
namespace WindowsFormsApplication1
{
public partial class frmBook : Form
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
public frmBook()
{
InitializeComponent();
}
private void lblStaffDetails_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void btnMainmenu_Click(object sender, EventArgs e)
{
this.Hide();
frmMainmenu op = new frmMainmenu();
op.Show();
}
private void dGridBook_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void frmBook_Load(object sender, EventArgs e)
{
this.tblBookTableAdapter.Fill(this.dbLibraryDataSet.tblBook);
this.tblBookTableAdapter.Fill(this.dbLibraryDataSet.tblBook);
con = new SqlConnection();
cmd = new SqlCommand();
cmd.Connection = con;
}
private void btnSaveBook_Click(object sender, EventArgs e)
{
con.Open();
cmd.CommandText = "insert into tblBook (Book_ID, Name, Authour, Category, Donater_ID, Section_ID) values ('" + txtBoxBookId.Text + "', '" + txtBoxBookName.Text + "', '" + txtBoxAuthour.Text + "', '" + txtBoxCategory.Text + "', '" + txtBoxDonaterId.Text + "', '" + txtBoxSecId.Text + "')";
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record is inserted", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void tblBookBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.tblBookBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.dbLibraryDataSet);
}
}
}
|
|
|
|
|
Two obvious errors that I can see:
1. You are risking the integrity of your database by using string concatenation for your queries.
2. You create a new form in btnMainmenu_Click , but then lose it as its reference goes out of scope.
I suggest you fix those two problems first, and then see what happens.
|
|
|
|
|
You create a Sql-connection without ever setting the connection-string. Add a con.ConnectionString = "blablabla" before opening the connection.
Member 13683765 wrote: cmd.CommandText = "insert into tblBook (Book_ID, Name, Authour, Category, Donater_ID, Section_ID) values ('" + txtBoxBookId.Text + "', '" + txtBoxBookName.Text + "', '" + txtBoxAuthour.Text + "', '" + txtBoxCategory.Text + "', '" + txtBoxDonaterId.Text + "', '" + txtBoxSecId.Text + "')"; That's an abomination. It is unsafe as mentioned by Richard, due to SQL-injection. It is hard to update when adding a column and it will become a annoying thing to read if the string becomes long enough that you have to scroll in the IDE.
try
{
string MyConnectionStringHere = "";
using (var con = new SqlConnection(MyConnectionStringHere))
using (var cmd = con.CreateCommand())
{
con.Open();
cmd.CommandText = @"
INSERT INTO tblBook (
Book_ID,
Name,
Authour,
Category,
Donater_ID,
Section_ID
) VALUES (
@Book_ID,
@Name,
@Authour,
@Category,
@Donater_ID,
@Section_ID)";
cmd.Parameters.AddWithValue("@Book_ID", txtBoxBookId.Text);
cmd.Parameters.AddWithValue("@Name", txtBoxBookName.Text);
cmd.Parameters.AddWithValue("@Authour", txtBoxAuthour.Text);
cmd.Parameters.AddWithValue("@Category", txtBoxCategory.Text);
cmd.Parameters.AddWithValue("@Donater_ID", txtBoxDonaterId.Text);
cmd.Parameters.AddWithValue("@Section_ID", txtBoxSecId.Text);
if (1 == cmd.ExecuteNonQuery())
{
}
else
{
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
A few notes;
- You'll still need to set a connection-string in the example, but you don't need SqlConnections in multiple methods, or as a member-variable. It will be closed when exiting the "using" statement.
- You want the complete exception-text; it will tell you where and more.
- Those column-names using up many lines may seem excessive to you; go stand on such a line in the IDE and press Ctrl-X. Move the cursor down two strokes and press Ctrl-V.
Good luck
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
What is the difference between unit tests, integration tests, acceptance tests, functional tests and regression tests?
|
|
|
|
|
|
They test different things; like a tire-test, a motor-test and a customer-satisfaction-survey to a car-salesman.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Up-voted for possible mix of analogy and irony.
I fear the OP here may be headed for an emissions-test fail in the job interview.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
You think he'll blow it? Exhausting
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Until you put in some effort to educate yourself by doing some basic research, there will be no difference.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|