|
It's not nice - if you have to use a static, it's probably a bad design!
And what happens if you have multiple threads, now or in the future? The approach fails, perhaps very badly.
Instead, I'd provide an optional paramater:
public void MyMethod(...list of parameters..., bool fullMethod = false)
{
} And then only call it with the full version when I needed it.
Why are you trying to do this? It sounds as if you have control of the calling and called ends, so why do you need to complicate things this much?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hypot.. hypohth.. hyph.. imagine it to be a brownfield
There is a succesfull application that suddenly needs branding; easily done, but what about the helper routines? Your executing assembly is not you. The calling one is not you. One needs to cater customer #1, the other a politician.
How do you distinguish the green UI from the brown one? Higher up in the tree of assembly references, how would you know whether to output green or brown text? If there's some intermediate shared assemblies, things quickly escalate.
So, if the stacktrace contains a reference to the entrypoint of the login, we know whether or not we are dealing with #2. If they are working on a licensing-scheme then all bets are off, offcourse.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I see nothing wrong with a static property, so long is its setter is protected by a mutex of some sort, which could be as simple as a lock ( object ) statement, where object is a private static object in the same class. (To avoid a deadlock, the object that gets locked must be separate from the property being set.) This is standard practice for a lazy initialized Singleton.
|
|
|
|
|
NJdotnetdev wrote: I have a dll which is called by the exe application from two different places. A managed or unmanaged library?
Do note, you cannot load the same assembly twice in the same AppDomain.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It's managed and loaded once at a given time.
|
|
|
|
|
Sorry, was thinking of the physical location of the assembly; you're referring to from where it is called in code. Since there is an overload, why not simply add another parameter to distinguish?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello people,
Currently working for a corporation in the KPO business.
I have an opportunity to work for .Net/Java projects for the company provided I show some programming skills. I need to undergo interviews/tests to ascertain my potential or the lack of it.
I request the fellow programmers here to please share on how to go about getting started off with programming.
-What books to read
-Internet resources
-How to develop programming logic
I will be grateful for any help or advice provided.
|
|
|
|
|
Books: any of the Wrox or Addison-Wesley are good. But whichever you chose, start at the beginning, and work through to the end, doing all the exercises on the way. That helps to "fix" the knowledge better than just reading. Avoid anything with "in XX days", multiple exclamation marks, or "For Dummies" in the title.
Internet resources: Can't help there, I don;t use 'em for learning as they are generally far too shallow. Video tutorials in particular have all been a waste of time in my experience.
Programming logic: Practice, practice, practice. It takes time, and quite a lot of it. Experience is the only way to develop this; there are no short cuts at all. Hopefully the exercises in the book(s) you read will have provided some of this, but there is no substitute for practice and experience here.
Just bear in mind that even the best coders had to start small, and we were all rubbish when we wrote our first code! (even if we thought we were Coding Gods )
Good luck!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Member 11972995 wrote: Internet resources Charles Petzold's .NET Book Zero[^] is a good introduction to C# and .Net. For Java you could start at
The Java Tutorials[^], there is one that starts from the very basics. Following either of these should quickly help you to find out whether you have an aptitude for development work.
Member 11972995 wrote: How to develop programming logic Unfortunately that is something inherent in your brain, if you don't have it then no amount of studying will create it.
|
|
|
|
|
I also recommend the Wrox books. It takes a while though, they tend to be pretty big. Also they just teach the "mechanics" of coding, the architecting of code and solutions is a skill that you can't really be taught, it develops over time and by learning from your mistakes. Also I'm a firm believer that coding simply isn't for everyone...you need a certain way of thinking, a calm and logical way of looking at things. We can't all be doctors or lawyers, or pro athletes, and we can't all be coders either. You'll only know if you have an aptitude for coding by starting. However here is a pro-tip...if you have to ask a question on a forum that you could find the answer to in 5 seconds by putting your query into google instead, then coding probably isn't for you. If you think telling someone something "doesn't work" is ebough information for them to solve your problem, then coding probably isn't for you. If you think telling someone your code has an error but doesn't think the error message or the line it occurs on is relevant to solving the problem, then coding probably isn't for you
|
|
|
|
|
Apart from what others have said, I would like to share my own views for such conditions when someone who doesn't have any background for programming or how computer actually works. I would like to straight away reject the request to teach them programming with a tip, to get yourself trained in the same field or a better one.
Programming cannot be learnt in a matter of month or even a year. Cramming is never going to help you out, so even if you have a great mind and can remember everything that an API documentation has, even then you are not a good candidate. I have been learning programming, creating applications, some for companies, some for my own devices. It is a matter of like 5 years now. But still I count myself in a learners category, beginners.
Books, internet resources etc is just a painful way to learn something. I learnt everything from Internet and by hit-and-trial methods. That was a lot painful, as if something isn't clear I had to search more for this. Now the frameworks that you are talking about are totally opposite with just one common thing, "byte-code". JVM and .NET are two different frameworks, they have different languages and different structures. Learning either one of them would require you at least 6 months. 1 year collectively. Then, the interviewer would like to ask you questions such as, "What is the different between String and string", "What is difference between value-types and reference-types?" or even worse, "What is difference between out and ref keywords?".
Until you have experience using them, you cannot answer them. Indirectly you are simply wasting your own time and theirs. As for the final question, programming logic is the logic to solve a puzzle. For example, you need to select adult people. What is the logic behind? Simple, those with age equal or greater than 18. In professional life these problems come even worse, like, select those candidates who are male, adult, having a bachelors degree and so on. You would have to add filters to results.
So, I would like to suggest that you take a local course for programming, understand how computer works. If this one job goes out of hand, don't worry after a year or two when you are ready, you can apply for this job or same. But make sure you are ready.
1. Books, in this case I would recommend that you ask the institute you are going to. They would guide you better.
2. In case of C#, I cannot think of anything better than MSDN. It is a bit technical, to break it down to pieces come back to CodeProject and search for related article. So read the .NET framework's library on MSDN[^].
3. Try asking a question, then solve it.
As far as the third part is concerned, last year I was a BSc student so I tried to create the functions that would give me answer for the numerical problems I had. For example, to find the acceleration for provided force and mass, I would write this,
double acceleration(double force, double mass) {
return (m != 0) ? force / mass : Double.PositiveInfinity;
}
The above function has most of my experience,
1. Writing short code, long and memory inefficient code is bad code.
2. Checking when dividing... DivideByZeroException gets raised mostly.
3. So on.
I hope you get the point, if you are so much interested in learning programming, then learn for a year or two. Computing is not about money, or jobs, it is about your interest. The more you have the better you serve.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I found these[^] courses to be some of the best ones on Introductory Programming, in this order - Programming Methodology, Programming Abstractions and Programming Paradigms.
The first one, Methodology, is by an instructor named Mehran Sahami, who teaches this in a really understandable way, and keeps the sessions extremely lively.
The latest software resources for these will be available at the Stanford University CS106a and CS106b sites.
|
|
|
|
|
Hi,
I would like to store data in multiple list and get them back.
I read a file containing measure of 5 sensors, I would to store all the acquisition in List (one by sensor).
And after I need to read them back.
I don't know the number of acquisition that why I would like to use List.
Thks
|
|
|
|
|
I'm not sure exactly what you are trying to do, but it's simple to create a List of Lists:
List<List<IndividualSensorReading>> sensorData = new List<List<IndividualSensorReading>>()
foreach(SetOfSensorData data in MySensorData)
{
List<IndividualSensorReading> readings = new List<IndividualSensorReading>();
sensorData.add(readings);
foreach(IndividualSensorReading reading in data)
{
readings.Add(reading);
}
} If that isn't what you are trying to do, then perhaps an example would help?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
sdecorme wrote: I would to store all the acquisition in List (one by sensor). And after I
need to read them back. If it is in memory, I'd recommend a Dictionary<int, List<whatever>> ; the int would refer to the index of your sensor (or use a string to identify them for something readable), containing a List with an object to represent the measurement. If it is a singular integer, then int would be enough.
You do not declare all variables of that complex type; inherit your own type from it and use that;
class MyComplexCollection: Dictionary<string, List<MyObject>> { }
...
var mcc = new MyComplexCollection();
mcc.Add("bla", new List<MyObject>());
mcc["bla"].Add(new MyObject(42)); If you really need the data then stream it to a file and flush after every write.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello,
I am trying to implement a chart in word using Microsoft.Office.Interop.Word.Chart .
I am able to generate a 2 dimensional chart with a x-axis and a y-axis but i am not able to add one more y-axis on the right side (secondary y-axis). can we achieve this by using Microsoft.Office.Interop.Word.Chart?
If YES, Please guide me in solving that issue else it will be a great help if you can provide any alternative.
Regards,
Santosh.
|
|
|
|
|
santosh kumar dash wrote: can we achieve this by using Microsoft.Office.Interop.Word.Chart? According to the documentation[^], yes.
What have you tried?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy,
I have pasted my code please have a look.
can we draw secondary y axis with the help of ChartWizard method in word chart.
Microsoft.Office.Interop.Word.Chart wdChart = wordDoc.InlineShapes.AddChart(Microsoft.Office.Core.XlChartType.xlLine, para17.Range).Chart;
wdChart.ChartWizard(Source: missing1,
Title: "graphTitle",
CategoryTitle: "Time",
ValueTitle: "Temperature",
ExtraTitle:"check");
Microsoft.Office.Interop.Word.ChartData chartData = wdChart.ChartData;
Microsoft.Office.Interop.Excel.Workbook dataWorkbook = (Microsoft.Office.Interop.Excel.Workbook)chartData.Workbook;
Microsoft.Office.Interop.Excel.Worksheet dataSheet = (Microsoft.Office.Interop.Excel.Worksheet)dataWorkbook.Worksheets[1];
Microsoft.Office.Interop.Excel.ChartObjects ChartObjects = (Microsoft.Office.Interop.Excel.ChartObjects)dataSheet.ChartObjects();
Microsoft.Office.Interop.Excel.ChartObject chartObject = ChartObjects.Add(40, 1000, 700, 350);
Microsoft.Office.Interop.Excel.SeriesCollection seriesCollection = (Microsoft.Office.Interop.Excel.SeriesCollection)chartObject.Chart.SeriesCollection();
Microsoft.Office.Interop.Excel.Series series1 = seriesCollection.NewSeries();
series1.XValues = dataSheet.get_Range("A1", "B7");
series1.AxisGroup = Microsoft.Office.Interop.Excel.XlAxisGroup.xlSecondary;
Microsoft.Office.Interop.Excel.Series series3 = seriesCollection.NewSeries();
series3.XValues = dataSheet.get_Range("A1", "D7");
Microsoft.Office.Interop.Excel.Series series4 = seriesCollection.NewSeries();
series4.XValues = dataSheet.get_Range("A1", "E7");
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("A2", missing1)).FormulaR1C1 = "5";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("A3", missing1)).FormulaR1C1 = "10";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("A4", missing1)).FormulaR1C1 = "15";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("A5", missing1)).FormulaR1C1 = "20";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("A6", missing1)).FormulaR1C1 = "25";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("A7", missing1)).FormulaR1C1 = "30";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("B2", missing1)).FormulaR1C1 = "1000";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("B3", missing1)).FormulaR1C1 = "2500";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("B4", missing1)).FormulaR1C1 = "4000";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("B5", missing1)).FormulaR1C1 = "3000";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("B6", missing1)).FormulaR1C1 = "400";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("B7", missing1)).FormulaR1C1 = "300";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("C2", missing1)).FormulaR1C1 = "700";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("C3", missing1)).FormulaR1C1 = "500";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("C4", missing1)).FormulaR1C1 = "400";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("C5", missing1)).FormulaR1C1 = "300";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("C6", missing1)).FormulaR1C1 = "2500";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("C7", missing1)).FormulaR1C1 = "3500";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("D2", missing1)).FormulaR1C1 = "1100";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("D3", missing1)).FormulaR1C1 = "2150";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("D4", missing1)).FormulaR1C1 = "4100";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("D5", missing1)).FormulaR1C1 = "3100";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("D6", missing1)).FormulaR1C1 = "2100";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("D7", missing1)).FormulaR1C1 = "3100";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("E2", missing1)).FormulaR1C1 = "2100";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("E3", missing1)).FormulaR1C1 = "2050";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("E4", missing1)).FormulaR1C1 = "4000";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("E5", missing1)).FormulaR1C1 = "2100";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("E6", missing1)).FormulaR1C1 = "4000";
((Microsoft.Office.Interop.Excel.Range)dataSheet.Cells.get_Range("E7", missing1)).FormulaR1C1 = "2100";
wdChart.ApplyDataLabels(Microsoft.Office.Interop.Word.XlDataLabelsType.xlDataLabelsShowLabel, missing1, missing1, missing1, missing1, missing1, missing1, missing1, missing1, missing1);
dataWorkbook.Application.Quit();
Regards,
Santosh.
|
|
|
|
|
I wanted to understand how to call a type parameter's method from a generic class. So if one has a class List<T>
and the class has a sort() method, how can the nodes in the list be sorted using T's Compare() method. The List<T> class is in a library.
Since T is a user defined class the list's sort method may not know how to Compare nodes in the list.
Thanks.
binsafir.
|
|
|
|
|
If T is limited to an interface, you can cast it to that interface. Alternatively, you can mess with reflection.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
With the default approach, you would only be able to do this if T implements IComparable . Suppose that you have the following class:
public class Cmp
{
public string Name { get; set; }
} With the default List.Sort(); , you would need to ensure that the class looks something like this instead:
public class Cmp : IComparable<Cmp>
{
public string Name { get; set; }
public int CompareTo(Cmp obj)
{
if (Name == null) return -1;
return Name.CompareTo(obj.Name);
}
} Now, suppose that you cannot modify the underlying library? Well, Sort accepts classes that derive from Comparison , or that implement IComparer<T> so you can create a new comparer that might look something like this:
public class CustomCmpComparer : IComparer<Cmp>
{
public int Compare(Cmp x, Cmp y)
{
if (x.Name == null) return -1;
return x.Name.CompareTo(y.Name);
}
} Then, your Sort call would look something like this instead:
myList.Sort(new CustomCmpComparer());
|
|
|
|
|
Generics are functions that work regardless of the type they are bound to. If you need to call a method then your function is no longer generic as it can't be used with any type. In order to do this your types will need to implement an interface that has your method on it
public interface IMyInterface
{
bool Compare(object target);
}
public class MyClass : IMyInterface
{
public bool Compare(object target)
{
return true;
}
}
When defining your generic function you can now stipulate that the type used has to implement your interface
private void MyFunction<T>(T data, T data2) where T : IMyInterface
{
data.Compare(data2);
}
You can now call your generic method but it must be bound to an object that implements your interface, it is no longer 100% generic.
MyFunction<MyClass>(new MyClass(), new MyClass());
MyFunction<SqlConnection>(new SqlConnection(), new SqlConnection());
|
|
|
|
|
The zero parameter Sort method on List<T> expects that T implements IComparable<T> or IComparable interface. If it does not an InvalidOperationException will be thrown. If T does implement the interface then knowing this List<T> can cast T to IComparable<T> or IComparable and call the Compare method. No need for reflection and List<T>>otherwise doesn't understand much about T at all, other than that it either does or does not implement IComparable<T> or IComparable.
If you want your "generic" to be able to call a method on T that is not exposed via a known interface or subclass you will probably need to resort to reflection or use some other way of mapping to the target method. While List<t> does not do this, you can constrain the type parameter for your generic such that it must implement certain interfaces or derive from a certain class allowing your generic class to call the methods known to be exposed via the super class or interfaces.
|
|
|
|
|
If you define List<T> where T: Icomparable , I think the compiler will object if it doesn't.
|
|
|
|
|