« first day (1439 days earlier)      last day (3503 days later) » 

2:08 PM
Morning everyone.
 
mornin boss
 
Jez
doesn't C# actually reference the same object for the same string literal, or did I make that up?
so, string x = "hello"; string y = "hello"; - both vars point to the same string instance?
 
Hm?
I think you made that up.
 
Jez
weird, i could've sworn i remember something about that
 
While that scope exists there would be two memory locations that stored that variable.
If they both pointed to the same one, a change in x would force a change in y.
Pointers n shit.
 
Jez
2:11 PM
could've sworn c# did something like that with immutable strings
for saving memory or something
what about string x = "hello"; string y = x; ?
does it treat the string as a value type and copy the instance?
maybe that's the oddity i was thinking of
 
reference type
 
^
y is just initialised with the value of x in that case.
 
Jez
there is something odd about the way C# handles strings
 
Same eventuality.
 
Jez
@Sippy so it creates a 2nd string instance?
 
2:14 PM
Mhm
 
Jez
ah that's the oddity then
normally it would point to the existing ref type
for strings it's a special case
 
Are you sure ...
CustomObject x = new CustomObject();
CustomObject y = x;
 
if you reassign string, it creates a new reference type
string x = "x";
x += "y";
is basically:
string _x = "x";
string x = _x + "y";
 
Jez
but what about assignment?
@Sippy yes, it doesn't make a copy
with strings, it does?
 
Yes it does?
 
Jez
2:17 PM
does it?
 
If you change y it doesn't change x.
 
yes
 
Jez
so that's not normal reftype behaviour
 
You can specify ref if you want to do that
C# doesn't have inherent reftype behaviour O_o
 
Jez
yeah, that's the oddity about strings in C#, they feel like value types
@Sippy huh?
it has inherent behaviour for when you assign reftypes
 
2:19 PM
Saying y = x; makes a new object.
Not a pointer
 
Jez
..... is my brain freezing
 
I dunno mine feels like it is as well lol
 
Jez
MyComplexObject foo = new MyComplexObject { a = 2, b = 3 }; var bar = foo;
that creates 2 MyComplexObjects???
 
Yes
 
Jez
surely not
 
2:20 PM
In C# it does.
 
Jez
it would have to copy MyComplexObject
i think you're wrong.
 
wait wat
Are you asking if it creates two instances or two classes?
 
Jez
erm, two instances. i dunno what you mean by two classes.
 
No that's what confused me
That would create two instances of MyComplexObject
Two identical copies.
 
it creates two pointers, both pointing to one MyComplexObject
 
2:22 PM
If it did that then a change in one would force a change in the other.
Unless C# is even more intelligent and only creates the other object in memory when the two are not identical.
 
if you do foo.a = 5 and bar.b = 5, both foo a/b = 5 and bar a/b = 5
 
In which case I didn't know it did that.
 
Jez
@NETscape ok that's what i thought. i guess im not going mad
but strings are an exception, as C# copies the immutable string instance
 
@NETscape Pretty sure this is wrong.
 
Do any of you know how to make it where when you click on a button in a website it will open an application on your phone?
 
2:25 PM
Can you explain to me why changing one of the pointers will not force a change in the other in that case?
 
how do you think "forcing" a change happens?
 
Jez
why would it?
 
183
Q: Launch custom android application from android browser

Parimal ModiCan anybody please guide me regarding how to launch my android application from the android browser?

 
foo
     > MyComplexObject
bar
 
Jez
there should be 2 chevrons
really
 
2:26 PM
they are both pointing to the same object
 
Jez
yeah but they're 2 pointers which is why one can be changed
without the other
 
if you change one object, the other pointer pointing at the object is also changed
 
@Sippy Thank ya
 
If you have two pointers, then making a change to the object being pointed to would change both.
Exactly
 
Jez
i thought i'd forgotten my C# fundamentals :-)
 
2:27 PM
That is not what happens in C#.
 
Jez
yes it is
 
If you do Object b; var c = b; then you can modify c without changing b.
Go try it xD
 
Jez
im trying it now
 
no, you can't
I'm confused
 
haha
 
2:28 PM
I AM SO SURE YOU CAN
If you can't then my understanding of C# is about to be destroyed.
 
c and b are the same object. If you change it it will change
 
Jez
if this stupid project didnt take 500 years to compile i would have an answer by now
 
Assume Custom has int1 and int2
    Custom c =  new Custom();
    c.int1 = 5;

    var b = c;
    b.int1 = 1;

    Console.Log(c.int1);
 
            MyComplexObject foo = new MyComplexObject() {A = 5, B = 3};
            var bar = foo;
            bar.A = 3;
            Console.WriteLine(foo.A);

    public class MyComplexObject
    {
        public int A = 0;

        public int B = 1;
    }
foo.A is 3
 
@Sippy if Custom is a class, it should print 1
 
2:31 PM
@Sippy it would print 5, because in1 != int1
 
Well, shit.
Lol netscape
Fukin typos!
 
@NETscape Is that allowed? fields in initializers that is
@Sippy Also, this isn't js :P
 
compiled and ran for me... i wasn't sure haha, i was just being lazy and crossing my fingers
 
Jez
yep, im right
stop misleading me @Sippy
 
Well there goes my understanding.
@Jez Wasn't intentional :(
 
2:35 PM
would you like a hug sippy
 
@KendallFrey cri. What should I google to read up on this?
 
Jez
C# essentials
:-)
 
lel
 
Jez
thats the first proper C# book i read
it's nice and concise
 
I've never actually read a programming book to be fair. Reading the C# one might learn me some shit.
 
2:36 PM
@Sippy on what? reference types vs value types?
 
@KendallFrey I dunno, I thought that would create two distinct objects which is wrong.
As it's actually a reference.
 
C has pointers, C# has references
Pointer : Reference, IArithmetic
 
Jez
and C++ has both :-P
 
How can I make a winform interact with a windows service
 
hey now, C# has values too ;) And you can use pointers in an unsafe block
 
2:39 PM
Im looking for simple approach, I saw stuff about remoting but it looks so complex
 
@meda via interprocess commuinication of some sort
 
@meda it's only complex until you understand it.
 
@EvanL yes I know, I just want the winform to read a string from the windows service
I tried using a DLL , but I think I got confused
 
what is a public sealed class?
 
@DemCodeLines it's a class that cannot be inherited.
but due to it being public, others can access it.
 
2:41 PM
@KendallFrey where can I find a simple example
 
No
Just google something
@DemCodeLines It's a class, it's public, and it's sealed. Which part is confusing to you?
 
sealed
 
@DemCodeLines Means you cannot inherit the class.
 
@KendallFrey can a DLL achieve this
 
just said that...
 
2:43 PM
@EvanL Yeah, that was a reply to Kendall Frey
 
Oh gotcha.
 
@meda I... think so, but your question is so broad I don't even
 
Snarky as usual ;)
 
@KendallFrey my windows service reads an rss feed, I just want to display it in my winform, its simple not broad
 
No, that's really broad
There are many ways to communicate between different programs
 
2:45 PM
@meda is the service hosted on the same computer as the winform?
 
I know, what should I elaborate on, they both run on the same machine
 
And you haven't actually said what is is you want to do
@meda Have you used google?
 
@EvanL Its a solution I have with a win service project and a winform projectct
@KendallFrey of course I did
 
What's the difference between internal List() vs public List()?
 
One is internal, one is public, try google.
 
2:47 PM
internal is internal, public is public
 
internal means it can only be accessed from its own assembly (namespace).
 
What don't you understand?
It looks like you're trying to read documentation. Would you like some help with that?
 
I see only over complicated stuff, Im sure There is a simpler way
 
and before you ask protected means it can only be accessed by it's children.
@meda it depends on what you consider complicated...
 
just dont mix public and private, you can get arrested
 
inb4 what does internal protected mean.
 
@CharlieBrown lol don't show your privates in public
3
 
internal is the modifier for external visiblity, protected is for inheritance
 
@user1112560 internalprotected or protectedinternal?
 
2:49 PM
and make public properties to expose your privates in case other publics want to touch your privates
 
working from home can be boring, no more chatting at the watercooler
 
public GetMyPrivates()
 
Anyway, to test with the null in this line?
var date = responses.FirstOrDefault(obj => obj.Label.Contains("Date Signed")).Value;
 
room topic changed to C#: The water cooler for remote workers [.net] [asp.net] [asp.net-mvc] [c#] [entity-framework] [linq] [visual-studio] [wcf] [wpf]
 
2:51 PM
For some odd reason it says it is null.
 
@KendallFrey I'm under the impression that the order of the keywords doesn't matter in that case. Both Compile.
 
I have a simple entity that I'm not connecting to my Entity Framework 6 context. I'm able to save it to the database with a simple "INSERT" sql command. In an integration test, I'm trying to check if that item got saved to the database by doing a var count = context.Database.ExecuteSqlCommand("SELECT COUNT(*) FROM table");, but that count variable is always coming back as -1. I've put in a break point, and see that the item is being saved to my table. What am I missing?
 
@KendallFrey perfect
 
@user1112560 I think you mean protectedinternal
 
@KendallFrey lolololol
 
2:51 PM
@KendallFrey I just tried, both compile.
 
I think there was another one, internalprotected or privateinternal
 
internal privates? I don't have those...
 
@krillgar why the raw sql, why not context.Unicorns.Any()
 
@Greg
var date = responses.FirstOrDefault(obj => obj.Label.Contains("Date Signed"));
if( date != null )
    var stuff = date.Value
 
@Greg responses doesn't contain the droids you are looking for
@EvanL Congratulations, you're a man
 
2:52 PM
Yay!
 
@KendallFrey That responses is a field from Xml.
 
@EvanL dont get me wrong Im noobie programmer, but here are some example I found
 
@Sippy what's so funny?
 
@CharlieBrown Because it's such a simple one-time use object that's just a quick dump to the database. It's a simple load table that a Stored Procedure is going to process, and then load the data into a table that has the actual entities we'll be using.
 
any entity framework gurus around?
 
@NETscape I have that, down lower in my code. Except as it tries to hit that, it fails.
 
@meda maybe go with WCF or some sort of RESTful interface.
 
@meda why did you make it a service? do other programs communicate with it?
 
@DemCodeLines demcurdloans plz
 
2:54 PM
but then you'll have to expose an API
 
Yes I have it as a service, and I would like the winform to just be a client to display latest feed
 
@NathanLoding For the most part here, though that is the topic of my question. What's up?
 
Is that the book am looking for?
 
2:56 PM
@NETscape its a service because I want it to run after reboot
 
@DemCodeLines I enjoyed this.
 
and I dont like schedule tasks
 
@krillgar ExecuteSqlComand has no return value
or does it...hmm
 
@krillgar - getting annoyed with context - i have a parent object (quote) and quote items (with a fk to quoteid to set up the relationship) - when i initially insert a new quote with items on it, it works; if i update that quote, the items get inserted AGAIN instead of updated ... and then if i try to null out that navigation property and save it separately, it says it already exists in context with that primary key
i'll get a pastebin or something set up, that was a lot of words
 
@CharlieBrown It has a return type of int. msdn.microsoft.com/en-us/library/gg679456(v=vs.113).aspx
 
2:57 PM
@NETscape Does that make sense?
 
@NathanLoding That sounds like a complex issue. Have you tried asking a question on here and including your code? Your Models and Configurations (if you're using Code First) would be necessary.
 
@krillgar The return type is the result, not something you queried for
 
@krillgar - if no one here had an answer i was going to post the question to SO, but i haven't yet
 
Jez
getting on a bit now, though. but it's how i first learnt C#. i cant stand those giant 1000 page books :-)
 
2:59 PM
@krillgar you should be using SqlQuery<int> instead
 
Jez
it's on my shelf next to The C Programming Language
 
@NETscape So, a couple of the nodes don't have the node label I posted above, which is why it is failing. So it causes the entire projection to fail.
 
@NathanLoding likely you are not loading the entity in context prior to changing/updateing it
 
@CharlieBrown I was looking at that too, and it gave me a query object.
 
@Jez thanks :)
There will be newer editions I suspect
 
Jez
3:01 PM
nah, they released that 12 years ago
 
@Charlie
oops
 
Jez
so much has been added to C# you'd need to double the size of the book for modern C#
 
@krillgar context.Database.SqlQuery<int>(SQLQUERY).First()
 
@NathanLoding I agree with @CharlieBrown. I'd check that first. If that still doesn't work, then you'll probably have to post a question. There's so many little things that could be wrong. But it's so much easier once you figure out those minor issues.
 
@CharlieBrown - the error says it is already in context with that primary key, which is why i'm confused when it duplicates
 
3:02 PM
Head First C# is my favorite
 
@CharlieBrown Awesome! Thank you. :)
 
i prefer Head First myself. but the book isnt all that great
 
Jez
Pages: 1100
:-O
hell no
 
@CharlieBrown dis is a naughty thing to do is it not?
When you have access to LINQ
 
Jez
C# Essentials 216 pages
 
3:04 PM
Depending on what you're trying to do with the language, you might be better off to read a book on a specific problem set in C#. You'll get more "real world" coding with the language, and see how things work. But have the other book there as a resource when you get mixed up.
More pages = more insight.
 
@Sippy yep
 
Gotta run. Good luck @NathanLoding
 
thanks
 
Jez
more pages = more boredom
read c# essentials, then get learning by doing
 
@NETscape Would I have to do some ternary:

var date = responses.FirstOrDefault(obj => obj.Label.Contains("Date Signed")).Value;

Into:

var date = responses.FirstOrDefault(obj => obj.Label.Contains("Date Signed")) == null ? date == null : responses.FirstOrDefault(obj => obj.Label.Contains("Date Signed")).Value;
@NETscape Something like that?
 
3:09 PM
@Greg are you trying to get null or a default datetime or what?
 
do it just as i posted? that is too long and ugly
 
@CharlieBrown So I have a couple Xml Documents that don't contain the label Date Signed all the others do. As we transitioned the system, but the first code posted hits a null so it automatically throws the a NullReferenceException as soon as it hits date. Which causes everything else to fail. So I have to test to make sure the node actually exist so it has a value.
@NETscape Can't, if the node doesn't exist then it throws an error in parsing. It has to be empty for the way your talking about to work.
@NETscape It can't find the node period, so it just fails.
 
what node?
 
the code i posted and what you posted are essentially the same
you have to wrap everything inside the if statement
var check = responses.FirstOrDefault(obj => obj.Label.Contains("Date Signed"));
if( check != null )
{
    var date = check.Value;

    // existing code
}
 
<Response>
<Label>Date Signed:</Label>
<Value>09/23/2014</Value>
<Type>Date</Type>
</Response>
<Response>
<Label>Time Signed:</Label>
<Value>08:21 AM</Value>
<Type>Time</Type>
</Response>
 
3:14 PM
anyone ever get back pain at work? D;
 
just deserialize to a c# class and call it a day
 
not sure if normal or my chair is just wank
 
@CharlieBrown That elemen
 
let c# do that hard work
 
@CharlieBrown That is what I'm doing, but the Label mentioned doesn't exist so it throws it off.
            foreach(var submission in model.Submissions)
            {
                // Will use Ternary Operation, if Response.Response has a null will call secondary descendant.
                var responses = submission.Sections.SelectMany(obj =>
                    obj.Screens.Screen.Responses.Response == null ? obj.Screens.Screen.Responses.Responses.Response.Select(response => new { response.Label, response.Value, response.Type })
                    : obj.Screens.Screen.Responses.Response.Select(response => new { response.Label, response.Value, response.Type })).ToList();
 
3:15 PM
thats not deserialize, you are parsing
 
That code above, is being called in here:

        public void ParseToModel(string file)
        {
            if (string.IsNullOrEmpty(file))
                throw new ArgumentNullException();

            XmlSerializer serialize = new XmlSerializer(typeof(CanvasResult));
            using(FileStream stream = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                using(XmlReader reader= XmlReader.Create(stream))
                {
                    CanvasResult model = serialize.Deserialize(reader) as CanvasResult;
 
there are so many chances for null ref and errors in that code
ParseToDatabase(model);
 
@CharlieBrown Well, the code is supposed to exist. But our transition caused some of the submitted Xml to not contain the Label that contains "Date Signed / Time Signed" but all our other ones still exist.
@CharlieBrown Normally, if something is null it is fine. The property just grabs it like normal. The node actually exist, but- The node doesn't exist so it doesn't even assign null just throws NulLReferenceException
@ton.yeung When I fix the current cluster fuck enough for it to be stable enough to where they don't need changes.
@ton.yeung The whole company relies on this, so it is business critical.
@ton.yeung About forty, which is about two-four months worth of work tops.
 
you shouldn't be calling .Value right away for any of those calls if you're going to do it that way
because if at any time there is an element missing your code will break
you should be getting first or default, check if its not not, if its not, then get the .Value, for each of those elements
or just deserialize as Charlie was saying
 
@NETscape What do you mean?
 
3:23 PM
responses.FirstOrDefault(obj => obj.Label.Contains("Date Signed")) can return null right? Right. So null.Value is going to throw an error
 
@NETscape The problem with deserialize is the third party API gives me:

- Label, Value, Type

So I've got a ton of date that constantly repeats itself within the API.
@NETscape Well, if the node existed that contains that it wouldn't matter. The code that validates that is fine. But the node doesn't exist.
 
exactly..........
thats why you have to check for null
 
@Greg Any problem with creating your own extension for that?
 
@NETscape Well, when I built it- it was always supposed to exist.
@user1112560 ?
@NETscape So, just leave .Value then check for null.
var date = responses.FirstOrDefault(obj => obj.Label.Contains("Date Signed"));
DateTime validatedDate = DateTime.Now;
DateTime.TryParse(date.Value + @" " + time, out validatedDate);
So I should just do something like that?
 
        public static TSource Test<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, Action<TSource> ifValueExists)
        {
            var value = source.FirstOrDefault(predicate);
            if (!EqualityComparer<TSource>.Default.Equals(value, default(TSource)))
                ifValueExists(value);

            return value;
        }
OK, I can't format code + reply in chat.
        IEnumerable<string> strings = new List<string> { "a", "b", "c" };
        bool hasA = false;
        strings.Test(a => a == "a", (a) => hasA = true);
 
3:37 PM
@user1112560 Well, that could avoid excessive if validation. Which is nice.
@user1112560 Not very expressive though.
 
Well, Rename to FirstOrDefault and add some XML DocComments
 
Basically, building that method and wrapping the call to the node element could be useful.
 
Admittedly I'm horrible at naming things.
        strings.FirstOrDefault(a => a == "a", ifValueExists: value => hasA = true);
looks horrible to me though. Named parameters look awful with lambdas
 
3:57 PM
that sucks.
It loads the music into the background task, but then never takes it out. As a result, when you close the app by forcefully closing it, the music continues to play in the background.
 
@DemCodeLines That sucks
 
@Greg Yes, yes it does.
 
@NETscape Thanks for your help, that does make sense. I'll write some better validation.
@NETscape I might do what was recommended an Extension Method that will take the value and return something better.
 
4:28 PM
So I have this:
public MyPlaylist Current
{
    get
    {
        if (instance == null)
        {
            instance = new MyPlaylist();
        }
        return instance;
    }
}
and this:
internal MyPlaylist()
{
    tracks = new String[3] { "ms-appx:///Assets/Media/Ring01.wma",
                           "ms-appx:///Assets/Media/Ring02.wma",
                           "ms-appx:///Assets/Media/Ring03.wma"
                        };
    mediaPlayer = BackgroundMediaPlayer.Current;
    mediaPlayer.MediaOpened += MediaPlayer_MediaOpened;
    mediaPlayer.MediaEnded += MediaPlayer_MediaEnded;
    mediaPlayer.CurrentStateChanged += mediaPlayer_CurrentStateChanged;
    mediaPlayer.MediaFailed += mediaPlayer_MediaFailed;
Problem is, what if I want the tracks to be supplied by code that calls it?
I could add a parameter to MyPlaylist() asking for a string array, but then instance = new MyPlaylist(); would fail, because I can't supply a parameter to it.
public MyPlaylist Current (String[] arr) won't work and would break the code, since it's a get property.
 
Why is tracks an array rather than a List?
 
That's not the point.
Even if it's a list, I can't add a Parameter on Current
 
Personally, playlist shouldn't be responsible for setting the current playlist. Especially not in the constructor.
For your problem, have one constructor initialising an empty playlist, and one with a string array to allow you to initialise the playlist with tracks.
 
@user1112560 Playlist should be an object or some sort of system that you supply a list of stuff to and it plays it one after another
 
4:51 PM
@DemCodeLines A playlist should be an abstraction over a collection of media files. It should expose methods allowing mutation of that collection, moving backwards and forwards in that collection, and allowing an arbitrary jump to a point in that collection. It should not be responsible for the playing of media, but it should expose a method to notify listeners that the current item has changed.
 
@ton.yeung Tigard, OR?
@ton.yeung Yes, I'm like ten to fifteen minutes away.
 
Partial methods. I have a problem.
My partial method that implements the body doesn't get called. WHY?
anything basic I'm missing here?
 
@Greg Nope, I don't.
 
have a database table and i need to get a last inserted row Id using MVC & Entity(ID is auto increment),can anyone please guide me how to do this ?
 
public override void Decode()
{
base.Decode();

BeforeDecode();

ReadBytes(offlineMessageDataId.Length);
raknetProtocolVersion = ReadByte();

AfterDecode();
}

partial void BeforeDecode();
partial void AfterDecode();
 
4:58 PM
@user1112560 Can you explain your extension method in more detail.
       public static TSource Test<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, Action<TSource> ifValueExists)
        {
            var value = source.FirstOrDefault(predicate);
            if (!EqualityComparer<TSource>.Default.Equals(value, default(TSource)))
                ifValueExists(value);

            return value;
        }
Trying to determine what the point of your EqualityComparer code is.
 
@Greg It calls FirstOrDefault normally, checks if the value is a "Default", and if it's not the default, will call the isValueExists method with the non-default value as an argument.
 

« first day (1439 days earlier)      last day (3503 days later) »