Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
H

haz13

@haz13
About
Posts
24
Topics
9
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Collections
    H haz13

    Thanks Luc for the useful info. I'm going to look into your suggestion about the IEnumerator. Such a steep learning curve only being new to c#:).

    Haz

    C# help data-structures question

  • Collections
    H haz13

    I have a car class with various fields some of which are colour, make, mileage. I then have a car collection which contains multiple car objects. public List<Car> CarCollection = new List<Car>(); What I want to do is pass the entire colour field array from the collection to a method CarData. (The method will be used to perform analysis on whatever array is passed in). CarData(CarCollection[].Colour); I can't get it to work. Is this possible (I guessing not)? Do I need to create a copy somehow? Please suggest an efficient solution to my problem. Thanks in advance for any help.

    Haz

    C# help data-structures question

  • Generic Collection &Method Problem
    H haz13

    Sorry Greeeg I don't understand how that would help what I'm doing (please explain more - maybe I haven't explined it very well)? Basically I need to itterate through all the collection object fields in turn. I have a method that does it for one of the fields, but instead of copying it 100 times and slightly changing the field refernces I was trying to create a method that was more generic (this is the bit I can't get my head around). CardDataCollection[0].Card1 CardDataCollection[1].Card1 CardDataCollection[2].Card1 CardDataCollection[3].Card1 CardDataCollection[4].Card1 CardDataCollection[5].Card1 to end of collection Then I need to do the same for the Card2 field And so on for each of the remaining Card fields upto 100 CardDataCollection[0].Card100 CardDataCollection[1].Card100 CardDataCollection[2].Card100 CardDataCollection[3].Card100 CardDataCollection[4].Card100 CardDataCollection[5].Card100 to end of collection Put another way I need one method to prevent me creating 100 very similar methods as described below.

        public static void CalcDataCard1()
        {
    
            int i;
    
            for (i = 0; i < CardDataCollection.Count; i++)
            { 
                if (CardDataCollection\[i\].Card1 == 1)
                {
                    //do data processing here
                }
            }
        }
    
        public static void CalcDataCard2()
        {
    
            int i;
    
            for (i = 0; i < CardDataCollection.Count; i++)
            { 
                if (CardDataCollection\[i\].Card2 == 1)
                {
                    //do data processing here
                }
            }
        }
    
        public static void CalcDataCard3()
        {
    
            int i;
    
            for (i = 0; i < CardDataCollection.Count; i++)
            { 
                if (CardDataCollection\[i\].Card3 == 1)
                {
                    //do data processing here
                }
            }
        }
    

    Thanks again for any help.

    Haz

    C# help tutorial csharp

  • Generic Collection &Method Problem
    H haz13

    I am really stuck trying work out and understand how to achieve the following. I have a collection of objects and want to peform some data analysis on each of the fields in turn using a method. The collection List<CardData> CardDataCollection = new List<CardData>(); CardData class contains fields called Card1,Card2,Card3 etc The code below has been simplified to show what I'm currently doing for one of the collection object fields (CardDataCollection[i].Card1).

        public static void CalcData()
        {
    
            int i;
    
            for (i = 0; i < CardDataCollection.Count; i++)
            { 
                if (CardDataCollection\[i\].Card1 == 1)
                {
                    //do data processing here
                }
            }
        }
    

    I need to perform the same exercise on each of the Card fields (for Card1 upto Card100) in the collection so I want to create a method that will allow me pass in some kind of reference to the collection object field (CardX). Note: I need access using the [i] as the data processing requires me to use for example [i-5] (i.e can't use foreach loops) I know what I want it do but just can quite get my head around how to do it. I'll try to explian below how I would change the code.

        public static void CalcData(reference to relevant card number field eg Card50)
        {
    
            int i;
    
            for (i = 0; i < CardDataCollection.Count; i++)
            { 
                if (Card50\[i\] == 1) //I know this can't be done
                {
                    //do data processing here
                }
            }
        }
    

    Please excuse any incorrect technical description as I'm only new to this C#. Thanks in advance for any help you can give me.

    Haz

    C# help tutorial csharp

  • Delimiters - Is there a simple way
    H haz13

    Thanks for that info guys, I'll go away and have a read up on it :)

    Haz

    C# help question

  • Delimiters - Is there a simple way
    H haz13

    Sorry Paul what do you mean by regular expressions? I'm only fairly new to this c#

    Haz

    C# help question

  • Delimiters - Is there a simple way
    H haz13

    I have a text file of the following format "apple","orange","pear" etc I have tried both char and string seperators but can't think of a way grab the data cleanly without including a " or , . I either end up with "apple" "orange" "pear" or "apple orange pear" The code I have been using. private static char[] charSeperator = new char[] { ',' }; private static string[] strSeperator = new string[] {"\",\""}; strArray = strLine.Split(charSeperator); strArray = strLine.Split(strSeperator,StringSplitOptions.None); Is there a simple way of grabing apple orange and pear from the text file, without having to do further data cleaning? Thanks in advance for any help you can offer

    Haz

    C# help question

  • Collection.IndexOf Method Question?
    H haz13

    I can't seem to get my head around the following. My Frequency class has two fields Data1 and Data2. public static List ColourFreqCollection = new List(); ColourFreqCollection.Add(new Frequency(1,2)); ColourFreqCollection.Add(new Frequency(3,2));etc Is it possible to now use the IndexOf method to look in the Frequency objects Data1 field and return the index if a particular number exists? ColourFreqCollection.IndexOf(don't know what to put here! -look in object data1 field and return index if true); Else what would be the best thing to do? Thanks in advance for your help.

    Haz

    C# question database help

  • How to add code to the default close/exit button on a form?
    H haz13

    The default close/exit button on my form instantly closes the form when clicked. However I would like the form to ask if I would like to save changes before closing when clicking this button. I can't work out how to get access to the relevant function - assuming that is what i need to do. How should I go about solving this problem? Thanks

    Haz

    C# help tutorial question

  • How to obtain the index of the last entry in a collection
    H haz13

    Thank you all :)

    Haz

    C# database tutorial

  • How to obtain the index of the last entry in a collection
    H haz13

    The pointy brackets containing the bits have been removed from the code by the editor in my previous reply, not sure how to override that when posting here.

    Haz

    C# database tutorial

  • How to obtain the index of the last entry in a collection
    H haz13

    Sorry, it is a generic collection. public static List SpinDataCollection = new List();

    Haz

    C# database tutorial

  • How to obtain the index of the last entry in a collection
    H haz13

    I am using collections for the first time and can't seem to figure out how to obtain the index of the last entry in the collection. I am guessing that I could use IndexOf() or LastIndexOf() methods, but not sure what to pass into the method. Here is the code public static class NumberProcessing { public static void UpdateSpinDataCollection() { SpinDataCollection.Add(new SpinData SpinNumber, CurrentNumber, Colour OddorEven); //Trying here to get index of last entry in collection SDCPointer = (short)SpinDataCollection.LastIndexOf(); //Test MessageBox.Show("SDCPointer:\t" + SDCPointer.ToString()); } }

    Haz

    C# database tutorial

  • How to convert short?[ ] to string[ ]
    H haz13

    Thanks for your speedy response. Your solution works really well in my program. :)

    Haz

    C# data-structures help tutorial question

  • How to convert short?[ ] to string[ ]
    H haz13

    I have an array full of values of type short?[] and want to display them in a MultiLine Textbox which requires values of type string[]. I can not figure out how to convert between the two value types. Here is my code that I thought would work but I get error - "can not convert type short?[] to string[] " NumArray = new short?[37]; public void SetFormData() { textbox1.Lines = new string[37] ; textbox1.Lines = (string[])NumArray; }

    Haz

    C# data-structures help tutorial question

  • I don't understand why I can't access a function from my Form instance from another class in the same namespace
    H haz13

    Forget that I had missed off the static keyword for a method in one of the static classes. Only just realised that all static classes should have static members. Thanks again for your help :)

    Haz

    C# help question csharp

  • I don't understand why I can't access a function from my Form instance from another class in the same namespace
    H haz13

    Thanks a lot for that, you were exactly right! I have slightly altered my code to cut down on the form reference passing. However when I try compling it it throws up an error - Compiler Error CS0120 - Error Message "An object reference is required for the nonstatic field, method, or property 'member' " and refers to line NumberProcessing.UpdateNumArray(this); I am guessing there is a problem with the "this" value? Any suggestions what is wrong??? Code is below. namespace RouletteV1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btn1_Click(object sender, EventArgs e) { NumberAttributes.Load(1); NumberProcessing.UpdateNumArray(this); } public void SetFormData() { tboxNumArray.Text = "Hello"; } public class NumberProcessing { public void UpdateNumArray(Form1 form) { form.SetFormData(); } } } Thanks in advance for your help :)

    Haz

    C# help question csharp

  • passing data to a textbox on a form using a method in a class
    H haz13

    Forget my last question. It has just clicked!!! Everything makes sense now :) Thanks

    Haz

    C# question visual-studio

  • I don't understand why I can't access a function from my Form instance from another class in the same namespace
    H haz13

    Thanks for that, everything has just clicked!!!! I understand where I was going wrong!! Fundamentals of oop :)

    Haz

    C# help question csharp

  • I don't understand why I can't access a function from my Form instance from another class in the same namespace
    H haz13

    Can anyone else help me with this?

    Haz

    C# help question csharp
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups