|
Maybe. But C# generics aren't C++ templates - you can't call two different overloads of a method based on the concretization of a generic type, because the concretization doesn't happen at compile time.
It would look like this:
public void Func<T>(Dictionary<T, int> somename)
But going by the description, there's a good chance you can't do this (or actually you could, but you'd have to manually test the type of T, and that's arguably a worse situation than you're on now).
|
|
|
|
|
I'd suggest looking at whatever part(s) of the functions that are truly identical (including types) and factoring that logic out of the two specific implementations, into a (private) sub-function.
Or use the generic implementation as suggested by Harold.
Either way, be careful to avoid falling back to an object -based (non-generic) implementation, because boxing-unboxing will impact your performance.
|
|
|
|
|
Hi,
With my Form_Load() I wish to set my 150'th Row as my TopRow, while the DataGridView gets visible. For that when I setup the currentcell Property its working fine. no prolem.
But when I try through the FirstDisplayedScrollingRowIndex() property its not working.
Its Not Working
dataGridView1.Rows[150].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = 150;
dataGridView1.Focus();
But the below is working
dataGridView1.Rows[150].Selected = true;
dataGridView1.CurrentCell = dataGridView1.Rows[150].Cells[0];
dataGridView1.Focus();
THANKS
|
|
|
|
|
Searched here on www.CodeProject.com
Searched the internet with Bing, Google, Yahoo, I forget whom else.
This was about what I found...
"Getter", noun: [1] A person or thing that gets, [2] stuff that's sprayed on the inside of vacuum tubes
The word is used frequently here on CodeProject. If it is defined somewhere with examples (in C#) then please point me to it.
Thanks
|
|
|
|
|
|
Thank you, for both the examples, and the description of how to find the answers on my own. I believe that I used a similar method for searching for the answers.
The first two examples left me saying "Duh"
The third example helped a little. I still don't have a clear definition in my head of just exactly what "Get" and "Set" are doing in terms of what byte goes where.
So, C# has this new way of setting values ? With the GET and SET thing ?
Please forgive my lack of vocabulary and nomenclature.
This is the way I had been thinking...
private void Button1_Command_01_Click(object sender, EventArgs e)
{
try
{
The_Action_For_Button1(The_Data_For_Button1);
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
But I'm off track with that kind of approach ?
What I'm after is an interface where the user clicks a button and the machine sends that command out the serial port. Currently, I'm trying to figure out how to arrange one method in one file to be visible to other methods in other files so that I can call the method from other methods in other files. (e.g., like subroutines in other languages)
C# has some sort of structure and rule system which is preventing me from doing that at this moment.
I'm still experimenting; will try the static word (suggested by another member in another thread earlier) in a few minutes from now.
modified 12-Nov-12 12:23pm.
|
|
|
|
|
|
in C# getters and setters are just syntactic sugar for get_Propertyname() and set_Propertyname(value) methods.
Think of a customer
public class Customer
{
private string name;
public string Name
{
get{ return this.name; }
set{ this.name = value; }
}
}
Usage
var cust = new Customer();
cust.Name = "Jamie";
MessageBox.Show(cust.Name);
|
|
|
|
|
Getters and setters are synctactic sugar. Behind the scenes, they map to special get_ and set_ methods. Okay, that sounds complicated, so let's have a look at what this statement actually means. Suppose you have a string property called BodyText. In C#, this would look something like this:
public string BodyText
{
get { .... }
set { .... }
} What the compiler does with this is to create 2 methods, set_BodyText and get_BodyText which would look something like this:
public void set_BodyText(string value)
{
...
}
public string get_BodyText()
{
return ....
} If you use reflection, you can actually find these methods. They are hidden from you in Intellisense because these methods (in the underlying IL) are marked as hidebysig specialname .
|
|
|
|
|
Pick up a book on C# and read - you would get an idea on properties and setters - getters.
|
|
|
|
|
Okay, so it's all about the learning curve ?
So then, like, C# takes a long time with repeated experiments and examples and so on before you are really competent to write something useful ?
|
|
|
|
|
C-P-User-3 wrote: So then, like, C# takes a long time with repeated experiments and examples and so on before you are really competent to write something useful ?
No. Your earlier work will probably seem quite naive to you when you go back to it later on, but there's no reason not to be writing useful code early on.
|
|
|
|
|
As others have said, it's simply a way of getting a value using a property:
private YourType yourValue;
public YourType YourProperty
{
get{ return yourValue;
}
The next obvious question is why we use a getter. In the example above we could have just made yourValue public. The disadvantage of that is then yourValue can also be changed. In our code, it is read only as there is no corresponding setter.
Including a setter rather than exposing the variable still has advantages however. For example, we could include some validation, raise an event or start some other activity in the setter:
public event EventHandler YourPropertyChanged;
private YourType yourValue;
public YourType YourProperty
{
get{ return yourValue;
set
{
if(!yourValue.Equals(value))
{
yourValue = value;
OnYourPropertyChanged(EventArgs.Empty);
}
}
}
protected virtual void OnYourPropertyChanged(EventArgs e)
{
EventHandler eh = YourPropertyChanged;
if(eh != null)
eh(this, e);
}
Also, the getter could be static as in DateTime.Now , where it returns a value that is calculated on demand.
There are other advantages too, but that should be enough to get you going
|
|
|
|
|
So then, a "getter" without a "setter" is the way (a way?) for me to define a group of bytes that won't change during program execution ?
That is one of the things that I definitely want to have if at all possible; i.e., when the user clicks button 1, I want to be certain that the bytes in a certain group are the bytes that go out the serial port.
|
|
|
|
|
IF you want a collection of anything ( <T> ) I would use a ReadOnlyCollection[^] and expose that using a property.
|
|
|
|
|
Sounds like a job for a FIFO collection. Time to cue the Queue[^].
|
|
|
|
|
Hello
I'm using this code...
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Version version = assembly.GetName().Version;
...to get version of my application.
The result is: 1.0.0.24557, but I want to reduce a number of digits in MinorRevision so that my result look like: 1.0.0.24
Why there is 5 digits in MinorRevision? Is it possible to modifiy MinorRevision to be only on 2 digits so the next version will be 1.0.0.25, 1.0.0.26 etc?
Rene
|
|
|
|
|
Member 9141033 wrote: Why there is 5 digits in MinorRevision?
Version numbers consist of two to four components: major, minor, build, and revision. The major and minor components are required; the build and revision components are optional, but the build component is required if the revision component is defined. All defined components must be integers greater than or equal to 0. The format of the version number is as follows (optional components are shown in square brackets ([ and ]):
major.minor[.build[.revision]]
The components are used by convention as follows:
Major: Assemblies with the same name but different major versions are not interchangeable. A higher version number might indicate a major rewrite of a product where backward compatibility cannot be assumed.
Minor: If the name and major version number on two assemblies are the same, but the minor version number is different, this indicates significant enhancement with the intention of backward compatibility. This higher minor version number might indicate a point release of a product or a fully backward-compatible new version of a product.
Build: A difference in build number represents a recompilation of the same source. Different build numbers might be used when the processor, platform, or compiler changes.
Revision: Assemblies with the same name, major, and minor version numbers but different revisions are intended to be fully interchangeable. A higher revision number might be used in a build that fixes a security hole in a previously released assembly.
Source[^]
Right-click on the project in the solution-explorer, choose "properties", go to the "application" tab, click on the button "assembly information" - there you can edit the numbers.
|
|
|
|
|
Tnx for your reply!
In my "application" tab -> "assembly information" stands 1.0.0.44, and when I run my application, application shows 1.0.0.25
Why there is a difference?
|
|
|
|
|
Member 9141033 wrote: Why there is a difference?
The assembly is part of the application; every assembly has it's own version-number, and then there's the version-number of the app.
|
|
|
|
|
Is there any way to reduce a number of digits so that my Revision has 2 digits?
tnx
|
|
|
|
|
Did your previous post not show an example where you had two digits?
|
|
|
|
|
ooops! sorry, my bad...
application(.exe) shows 1.0.0.25969 and in project properties stands 1.0.0.44.
i want to reduce number of digits...
tnx
|
|
|
|
|
Come on! It's simple string manipulation! Convert the Revision number to a string and grab the left 2 characters.
Why is this being treated as rocket science??
|
|
|
|
|
Rocket science or not, if you want to help then help, and don't prance here...
|
|
|
|